title: Aop, Unity, Interceptors and ASP.NET MVC Controller Action Methods
body: <p>Using log4net we would like to log all calls to our ASP.NET MVC controller action methods.</p>
  
  <p>The logs should include information about any parameters that were passed to the controller.</p>
  
  <p>Rather than hand-coding this in each action method we hope to use an AoP approach with <a href="http://msdn.microsoft.com/en-us/library/dd140045.aspx" rel="nofollow noreferrer">Interceptors via Unity</a>.</p>
  
  <p>We already have this working with some other classes that use interfaces (using the <code>InterfaceInterceptor</code>). However, we're not sure how to proceed with our controllers. Should we re-work them slightly to use an interface, or is there a simpler approach?</p>
  
  <h2>Edit</h2>
  
  <p>The <a href="http://www.pnpguidance.net/Post/VirtualMethodInterceptorUnity12CastleDynamicProxyFans.aspx" rel="nofollow noreferrer">VirtualMethodInterceptor</a> seems to be the correct approach, however using this results in the following exception:</p>
  
  <pre>
  System.ArgumentNullException: Value cannot be null.
  Parameter name: str
     at System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, String str)
     at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)
     at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
  </pre>