TAGS :Viewed: 14 - Published at: a few seconds ago

[ Can I have multiple log4net configuration files? ]

Can I have multiple log4net configurations for the same program? Functionality similar to Spring's <import> element would be optimal. The idea here would to have multiple programs that have their own log4net configuration, as well as sharing a central log4net configuration file containing a shared error log (so that definition isn't repeated). Alternatively is this functionality possible with .NET Common Logging?


Related: log4net - configure using multiple configuration files

Answer 1


you can achieve this by using named repositories i think

log4net.LogManager.CreateRepository(repositoryName)
log4net.Config.XmlConfigurator.Configure(repositoryName, configFile)

then by using

LogManager.GetLogger(repositoryName,loggerName)

you can get the corresponding logger.

Answer 2


Not out-of-the-box. You must implement yourself the merging of different config files into a single XmlNode and pass this to log4net XmlConfiguratot.

An example is to be found here: http://www.kopf.com.br/kaplof/using-multiple-configuration-files-with-log4net