Search code examples
c#dlllog4netapp-configcommon.logging

C# DLL - Loading seperate app.config file for Common.Logging (Log4Net)


I am busy working on a C# library and I would like to make use of the Common.Logging with Log4Net, however, it looks for in the host applications app.config file for respective libraries settings.

Is there anyway of telling Common.Logging to look at a different config file?


Solution

  • you could execute this code once on applicatin startup:

    XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config"));
    

    you may add this to AssemblyInfo.cs with the same result.

    [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]