You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Peter <pe...@circle-consulting.co.nz> on 2009/09/25 04:11:37 UTC

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.



Re: Two assemblies using same Log4Net framework

Posted by Ron Grabowski <ro...@yahoo.com>.
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 <pe...@circle-consulting.co.nz>
To: log4net-user@logging.apache.org
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.