title: What is the best pattern for using same Log4net logger across many assemblies in a solution?
body: <p>I have a solution consisting of a main winforms app, with associated internally written class library dll’s from which I wish to log. This logging should performed by the same logger, regardless of whether the main UI client or the associated dll’s call this. The dll’s may of course be used by other apps that have different loggers in other solutions, but in these circumstances will have a different log4net config and maybe a different suite of appenders altogether.</p>
  
  <p>One approach would be to create a singleton within the main app and log from that, however since log4net is its own singleton, that can be referenced so as long as we pass the same string (or type) to <code>log4net.LogManager.GetLogger</code> we will be logging to the same destination (in my case I wish to use a RollingFileAppender). </p>
  
  <p>This works. However, given that the DLL will have a number of classes it would mean each class instantiation or static class from which we wish to log would require i) an argument defining the logger name (in order to log to the same destination) and ii) at each entry point would need to call <code>log4net.LogManager.GetLogger(loggerName)</code>.  </p>
  
  <p>What is the best pattern to use here? Would the correct approach be to create a singleton instance in each assembly? My concern here is that we will still need to pass in the logger name to each entry point for the dll, which seems like overkill. In order to avoid passing in the logger name, I might assume that it is always equal to <code>System.Reflection.Assembly.GetCallingAssembly().GetName().Name</code>. </p>
  
  <p>If this is all too difficult for log4net, are there other easier solutions such as the Enterprise Logging Block? 
  Or is the best solution an aspect oriented programming (AOP) approach?</p>
  
  <p><a href="https://stackoverflow.com/questions/576185/logging-best-practices/576420#576420">Reference for anti-pattern approach for singleton here</a> . </p>