I am using Prism 4 and want my various modules to register using log4net. At the moment, I have the following implementation of ILoggerFacade:
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 great, my modules have an ILoggerFacade that can be entered and registered through them, which end here and end in log4net. My problem is that the log entries lose information about the call site, because they use an instance of the CustomLogger registrar, so in the end they look like this:
System.Reflection.RuntimeConstructorInfo: 2012-10-11 15:41:07,486 [23] INFO - test log
Has anyone been able to solve this problem? I was thinking of passing in the type of the caller, but it seems like it is inconvenient to do this for every call to the log in my modules.
I cannot use .Net 4.5, therefore I cannot use CallerMemberNameAttribute .
Dutts source share