Intercepting methods with Ninject for error logging

I am currently working on a fairly large Windows Azure projects that among other things conatins a Web Role where I use Ninject as a dependency container. As the business logic library grew larger I found myself writing a lot of repeating boiler plate code to log exceptions in many important methods. I wantet to remove all the boiler plate code and create a custom attribute, say LogErrorAttribute with one simple goal: each method decorated woth this attribute should log info about any occuring exception.

IL weaving?

I have been using Fody for some time to implement the INotifyPropertyChanged calls for me in Windows Phone and Windows 8 projects so it was my first choice.

There is a Fody.MethodDecorator extensions that allows you to execute your code on a methods start, exit and exception. Writing the exception to Console is trivial, but I wanted to use a implementation of my custom ILogFactory.

[Read More]