I’ve got an MVC application where I use Try-Catch blocks throughout and I’m looking for an easy way to implement activity/error-logging based on a global boolean field. Does anyone know a way I can ‘extend’ the functionality of the Try-Catch code in order to add my own activity/error logging without having to go through and touch every block?
For example:
I’d like the the Try to automatically log certain items to my DB such as url, action, ids, parameters, IP info, etc,…
And the Catch to automatically log it’s Exception to another table in the DB.
Thoughts? Recommendations?
Thanks,
Peter
Create your custom action filter and decorate controllers or action methods with it.
http://msdn.microsoft.com/en-us/library/dd381609.aspx
Then use it