We had a very similar issue. We use NLog as our logging system and did not want to have to configure and maintain two different logging configurations.
Our solution was to build a bridging class and to configure it as the root appender for log4net.
For example:
Code:
/// <summary>uses nlog loggers to output the log messages from log4net</summary>
public class Log4NetToNLogAdaptor : IAppender
{
public void DoAppend(LoggingEvent loggingEvent)
{
Logger log = NLog.LogManager.GetLogger(loggingEvent.LoggerName);
Exception exception = loggingEvent.ExceptionObject;
string message = loggingEvent.RenderedMessage;
if( loggingEvent.Level >= Level.Critical )
{
if (exception != null)
log.FatalException(message, exception);
else
log.Fatal(message);
}
else if (loggingEvent.Level >= Level.Error)
{
....
}
...
}
}
and to configure the bridge (eg: in Application_Start):
Code:
BasicConfigurator.Configure(new Log4NetToNLogAdaptor());
You can then configure log4net loggers in your nlog configuration file in the same way you would configure nlog loggers:
Code:
<logger name="NHibernate.SQL" minlevel="Debug" writeTo="trace,file" final="true"/>
regards,
Paul.