I believe you are trying to reinvent the wheel, there are several tools to abstract the loggers from your code decoupling the logger framework from your code:
http://slf.codeplex.com/
http://netcommon.sourceforge.net/
Those are the most common in .Net applications.
Well now if you insist in using your own abstraction (which is valid), this is my suggestion:
First of all, I assume that you would have something like:
interface ILogger
{
void Debug(string message);
void Info(string message);
void Warn(string message);
…..
}
Ok so in your code you would inject a singleton reference of your logger, like:
x.For<ILogger>().Singleton().Use<MyLogger>();
Now, I usually prefer convention over configuration, but in the case of loggers, the configuration through a config file is a big advantage because when your code is in production, you will want sometimes to change the logging rules by disabling or enabling loggers, change the log-level, and enable/disable named loggers.
The easiest and most reusable way I have found to accomplish this is by placing the configuration in an external file as you commented, then I do not bother calling the XmlConfigurator
in code, because it is simpler to me just add a couple of application settings to my config file like this
<!-- Relative to the application root path -->
<add key="log4net.Config" value="Logger.log4net"/>
<add key="log4net.Config.Watch" value="True"/>
That’s it. Those application settings override your log4net configuration and they are easy to maintain. Your config file will look like:
<?xml version="1.0" encoding="utf-8" ?>
<!-- This section contains the log4net configuration settings -->
<log4net>
<!-- Define some output appenders -->
<appender name="LogFileAppender" type="log4net.Appender.FileAppender" >
<file value="webapp-log.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default priority -->
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
To configure more appenders: click here
In your projects you only need a reference to your logger abstraction component, and just in the web project (or windows application, it’s the same) add the log4net config file and just those application settings
Since you are creating a reusable component I would recommend you to setup an internal Nuget server in your organization (it’s just an IIS application) and use it to deploy your components, in this case the library containing the logger. Also it would be better if you create a different Nuget package containing only the application settings and the log4net configuration file, so you can install this Nuget package only in your web project