Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net - configure using multiple configuration files

I have an application consisting of a host and pluggable modules (plugins).

I want to be able to configure log4net for the host and for each of the other modules. Each of them should have its own configuration file and each will log to a different file.

Only the host has an App.config file. The plugins have their own config file containing the log4net config sections.

Calling XmlConfigurator.Configure from one of the plugins overrides the host's app.config log4net definitions.

Is there an easy way to append configurations instead of overriding them?

Thanks, Gai.

like image 441
Gai Avatar asked May 05 '10 17:05

Gai


People also ask

Where is log4net configuration file?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.

How do I initialize log4net?

Configuration InitializationConfigureAndWatch to initialize log4net setup as per the config setup in your main entry method like main method of program class. Method “ ConfigureAndWatch ” configures log4net using the file specified, monitors the file for changes and reloads the configuration if a change is detected.


1 Answers

It appears you already have found a solution that works for you. However, I've found a different solution which I consider to be "more ideal", so I'll post it here for whoever might find this question in the future.

log4net has a concept called repositories which can be configured separately. It's not very popular nor very well documented, but here's some documentation I found:

http://logging.apache.org/log4net/release/manual/repositories.html

Anyway, all you need to do is add RepositoryAttribute on your plugin assembly or assemblies with a repository name unique to that plugin and log4net will keep it separate from everything else.

like image 99
Tinister Avatar answered Oct 08 '22 00:10

Tinister