I am trying to implement simple logging with AOP approach with StructureMap.
Basically, I want to do what is asked in the question Castle, AOP and Logging in .NET with StructureMap.
CastleWindsor has the helpful IInterceptor
that you can implement and then control when the a method is called with the IInvocation.Proceed()
. Allowing you to perform logging before and after the call to the method is made.
How can achieve this with StructureMap? I have tired using a custom Interceptor
but the only handle you get is when the instance is created, not when a method is called on the instance.
Something like this would probably work for you:
Create a castle proxy interceptor:
Register this in you SM configuration to wrap all
IFoo
with a proxy:All calls to any method on all instances of
IFoo
will now be intercepted by theLoggingInterceptor
. You can of course filter which calls you want to log by inspecting the instance.