Mike-Ward.Net

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, including colored stack traces.

In many cases, you can review the original yellow screen of death that ASP.NET generated for a given exception, even with customErrorsmode 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.

It’s, “The bee’s knees ”, in my opinion and thanks to the Nuget package, a breeze to install.

Next, open your Web.config. You can remove the element that the ELMAH installer added near the bottom of the file.

The ELMAH installer modifies the Web.config to configure ELMAH. It does not configure where the errors are stored. There are many options including SQL Server and Oracle. I personally like to use files. Here’s an example configuration.

I also enable remote access. It’s convenient but be aware there’s a security risk.

Open the ELMAH dashboard and navigate to http://yourwebsite/elmah

Here’s an example dashboard:

Finally, I discovered a minor bug in Nancy where some accept headers can raise exceptions. On my site it was generating several hundred log messages a day. There’s a bug logged and it will likely be fixed in a future version of Nancy. In the meantime, you can modify your ELMAH configuration to remove these exceptions. Here’s the final form of the ELMAH configuration.