title: Intercept or Decorate calls to ILogger
body: <p>I'm currently using castle windsor, along with it's logging facility in my application.  </p>
  
  <p>However, in my logging I would like to include some contextual information that is not within the logged message, but stored within the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.remoting.messaging.callcontext(v=vs.110).aspx" rel="nofollow"><code>CallContext</code></a>.</p>
  
  <p>I have tried to do this by intercepting the calls to <code>ILogger</code> using the following:</p>
  
  <pre><code>internal class Program
  {
      private static void Main(string[] args)
      {
          var container = new WindsorContainer();
          container.AddFacility&lt;LoggingFacility&gt;(f =&gt; f.UseNLog());
          container.Kernel.Resolver.AddSubResolver(new LoggerResolver(container.Kernel));
  
          var logger = container.Resolve&lt;ILogger&gt;();
      }
  }
  
  public class LoggerResolver: ISubDependencyResolver
  {
      private readonly IKernel _kernel;
      private static ProxyGenerator _proxyGenerator;
  
      static LoggerResolver()
      {
          _proxyGenerator = new ProxyGenerator();
      }
  
      public LoggerResolver(IKernel kernel)
      {
          _kernel = kernel;
      }
  
      public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
      {
          return dependency.TargetType == typeof(ILogger);
      }
  
      public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
      {
          return _proxyGenerator.CreateInterfaceProxyWithTarget(_kernel.Resolve&lt;ILogger&gt;(), new LoggingInterceptor());
      }
  }
  
  public class LoggingInterceptor: IInterceptor
  {
      public void Intercept(IInvocation invocation)
      {
          //Some modification to message here
          invocation.Proceed();
      }
  }
  </code></pre>
  
  <p>But the variable <code>logger</code> is of type <code>NLog.Loggger</code> rather than the dynamic proxy I was expecting.</p>