Using an alternative source for your log4net configuration.

In a recent project I wanted to use the same log4net configuration for different applications/services running on the same server – and would rather not maintain the same config information across multiple app.config’s. I have also often found that the rather voluminous log4net configuration would be nice to factor out of the app.config file, just for the sake of readability.

Luckily it’s easy to do, like this:

log4net.Config.XmlConfigurator.Configure(newSystem.IO.FileInfo("e:\configs\log4netcommonsettings.xml"));

What I did in my actual project, was to make a one-line setting in each app.config, referencing the common configuration source:

<add key="Log4NetCommonSettingsFile" value="e:\configs\log4netcommonsettings.xml"/>

Advertisements
Posted in C#