I am using Prism 4 and want to allow my various modules to log using log4net. At the moment I have the following ILoggerFacade implementation:
public class CustomLogger : ILoggerFacade
{
private readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().GetType());
static CustomLogger()
{
XmlConfigurator.Configure();
}
public void Log(string message, Category category, Priority priority)
{
switch (category)
{
case Category.Debug:
_logger.Debug(message);
break;
case Category.Info:
_logger.Info(message);
break;
case Category.Warn:
_logger.Warn(message);
break;
case Category.Exception:
_logger.Error(message);
break;
}
}
}
This works fine, my modules have an ILoggerFacade injected and can log via that, which end up here and end up in log4net. My problem is log entries lose the call site information as they are using the CustomLogger's logger instance so end up looking like this:
System.Reflection.RuntimeConstructorInfo: 2012-10-11 15:41:07,486 [23] INFO - test log
has anyone managed to solve this problem? I have thought about passing in the Type of the caller but it seems a little clunky having to do that for every log call in my modules.
I am unable to use .Net 4.5 so can't use CallerMemberNameAttribute unfortunately.