Error Logging Modules and Handlers for ASP.NET (Webform/MVC)
I just implemented ‘Elmah’ for my ASP.NET MVC project. I’m using the SQL logging feature (a script comes with the download). A sample with asp.net webforms comes with the download.
I followed Darrell Mozingo’s blog post here http://darrell.mozingo.net/2009/02/19/elmah-with-aspnet-mvc/ for setting it up with asp.net mvc.
Additionally I used Dan Swatik’s excellent post on integrating Elmah using the controller/action ‘HandleError’ attribute to customize the HandleError attribute (see ‘Action Filtering in Mvc Applications’)
ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.
Once ELMAH has been dropped into a running web application and configured appropriately, you get the following facilities without changing a single line of your code:
- Logging of nearly all unhandled exceptions.
- A web page to remotely view the entire log of recoded exceptions.
- A web page to remotely view the full details of any one logged exception.
- In many cases, you can review the original yellow screen of death that ASP.NET generated for a given exception, even with customErrors mode turned off.
- An e-mail notification of each error at the time it occurs.
- An RSS feed of the last 15 errors from the log.
Check out the Elmah Wiki writeup by Simone Busoli for a good overview of the features.
Basically I signal all my errors (using a custom Exception object) to Elmah to help assist in an easy way to write errors to SQL, send emails out, and provide a rss feed of the errors. (I am still using Log4Net, but might just convert everything to Elmah)
This is a ‘must have’ for an asp.net application.