Two assemblies using same Log4Net framework

View: New views
2 Messages — Rating Filter:   Alert me  

Two assemblies using same Log4Net framework

by Peter-411 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

My main VB.NET application uses sets up and configures Log4Net.  It calls two
or three other assemblies and I want to "pass a reference" to the main app's
Log4Net instance to those assemblies so they log messages into the same log
file and respect the same configuration settings.  Is it correct to do this:

In the main app I have the following method call to my assembly:

  SetLog(mLog.Logger.Repository)

Where "mLog" implements the ILog interface.

In the assembly the SetLog method is:

  Public Sub SetLog(ByVal Repository As log4net.Repository.ILoggerRepository)

    log4net.Config.BasicConfigurator.Configure(Repository)

    mLog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod
().DeclaringType)
   
   End Sub

This seems to work OK but I'm unsure if it's a good thing to pass Repository's
between assemblies in this way.

Any and all advice would be appreciated.



Re: Two assemblies using same Log4Net framework

by Ron Grabowski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The main application should configure log4net. The other libraries should just create logging statements. You don't need to pass the repository between applications.


----- Original Message ----
From: Peter <peter_m@...>
To: log4net-user@...
Sent: Thu, September 24, 2009 10:11:37 PM
Subject: Two assemblies using same Log4Net framework

Hi

My main VB.NET application uses sets up and configures Log4Net.  It calls two
or three other assemblies and I want to "pass a reference" to the main app's
Log4Net instance to those assemblies so they log messages into the same log
file and respect the same configuration settings.  Is it correct to do this:

In the main app I have the following method call to my assembly:

  SetLog(mLog.Logger.Repository)

Where "mLog" implements the ILog interface.

In the assembly the SetLog method is:

  Public Sub SetLog(ByVal Repository As log4net.Repository.ILoggerRepository)

    log4net.Config.BasicConfigurator.Configure(Repository)

    mLog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod
().DeclaringType)
 
   End Sub

This seems to work OK but I'm unsure if it's a good thing to pass Repository's
between assemblies in this way.

Any and all advice would be appreciated.