I want to implement custom LogAttribute, which will log information at the start and end of each method in a class, also it should log error as well. I would like to apply the attribute over a Class.
I have seen PostSharp. But I would like to have my own custom log attribute, rather than using PostSharp or similar library.
Performance is the major key, the LogAttribute should not affect performance.
I have read about the IMessageSync, but it affect performance.
In MVC, we get CustomFilters, wherein we can have LogActionHandler, which will execute at the start and end of each Action method. I would like to implement similar in ASP.Net web Form.
Can anyone help me by providing some sample code.
Unity - Microsoft's IoC / Dependency Injection Container also allows Method Interception.
Here's an example of a "DiagnosticsInterceptor", that does the same as you want: http://hmadrigal.wordpress.com/2010/12/25/aspect-oriented-programming-and-interceptor-design-pattern-with-unity-2/
Pro: It's free
Con: It requires Unity / DI / IoC pattern. And your class Needs to have an Interface, or a virtual method.
Unfortunately that is NOT true for ASP.NET controls. So this method will only work for your custom class: See Intercept Unity 2.0 HandlerAttribute without an interface
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With