Specifying a Log4Net Configuration at Runtime

Log4Net provides a powerful logging schema that you can integrate into your development project. It is developed by Apache and is extensively in the Java world, with the original Log4j logging method being ported over to the Microsoft .NET environment.

Many of the code samples we reviewed recommended embedding the logging information into the app.config or the web.config files. We had a requirement to embed the logging capability into an application that worked with .DLL plug-ins. Each DLL plug-in required its own logging parameters and there was only one app.config for the overall “host” executable.

We achieved this by passing in a location of the configuration file and passed it directly into the Log4Net XmlConfiguration object as below.

log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(ConfigFileLocation));