views:

513

answers:

2

Using log4net we would like to log all calls to our ASP.NET MVC controller action methods.

The logs should include information about any parameters that were passed to the controller.

Rather than hand-coding this in each action method we hope to use an AoP approach with Interceptors via Unity.

We already have this working with some other classes that use interfaces (using the InterfaceInterceptor). 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?

Edit

The VirtualMethodInterceptor seems to be the correct approach, however using this results in the following exception:

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)
+1  A: 

Have you seen this?

Mark Seemann
A: 

not exactly what you are asking, but you might want to consider log4postsharp. maybe you will need this as well, but I cannot tell for sure as I did not use ASP.Net MVC so far

Stefan Egli