title: How to use log4net with Dependency Injection
body: <p>I'm trying to figure out what the right patter and usage of log4net is with a dependency injection framework. </p>
  
  <p>Log4Net uses the ILog interface but requires me to call </p>
  
  <pre><code>LogManager.GetLogger(Reflection.MethodBase.GetCurrentMethod().DeclaringType)
  </code></pre>
  
  <p>in each class or method where I need to log information. This seems to go against IoC principles and couples me to using Log4Net.</p>
  
  <p>Should I somehow put in another layer of abstraction somewhere? </p>
  
  <p>Also, I need to log custom properties like the current user name like this:</p>
  
  <pre><code>log4net.ThreadContext.Properties["userName"] = ApplicationCache.CurrentUserName;
  </code></pre>
  
  <p>How can I encapsulate this so that I don't have to remember to do it everytime and still maintain the current method that is logging. should I do something like this or am I totally missing the mark?</p>
  
  <pre><code>public static class Logger
  {
      public static void LogException(Type declaringType, string message, Exception ex)
      {
          log4net.ThreadContext.Properties["userName"] = ApplicationCache.CurrentUserName;
          ILog log = LogManager.GetLogger(declaringType);
          log.Error(message, ex);
      }
  }
  </code></pre>