Tallan's Technology Blog

Tallan's Top Technologists Share Their Thoughts on Today's Technology Challenges

A Brief Introduction to Error Logging Modules And Handlers (ELMAH)

Micael George

Overview

ELMAH is an open source project used to add error logging capabilities to an ASP.NET Web application. ELMAH essentially provides a means for logging and reporting unhandled exceptions in applications. I came across this very nifty tool while working with the MASS LEG team to create the Legislative Automated Workflow System (LAWS) application for the Massachusetts Legislature. We used ELMAH to uncover issues in the application that were producing unhandled and non-descriptive exceptions.  Using ELMAH, the dev team was able to use the stack trace of the exception to pinpoint and fix the problem. The following provides a brief description of how to set up ELMAH and enable & configure its error logging.

Setting Up

There are only a few steps to setting-up ELMAH. The first thing that should be done is to get the latest release of ELMAH and adding the ELMAH assembly to the Web application, referencing the Elmah.dll assembly compiled for the right version of the .NET framework.  The next and final step is to configure the Web application to use ELMAH’s HTTP modules and HTTP handlers.

In the Web.config file, one needs to add the following settings:

  • A <sectionGroup> element in the <configuration> element that defines a new section name, <gotdotnet.elmah>, with a section inside called <errorLog>, which has information about how to log exception information.
  • A <gotdotnet.elmah> section, with an inner section named <errorLog>, which contains type reference to the exception logger you want ELMAH to use, along with any settings specific to the exception logger.
  • An entry in the <httpHandlers> section indicating the path that, when visted through a browser, will render various views on the error log
  • An Entry in the <httpModules> section that adds the ErrorLogModule to the ASP.NET HTTP pipeline. (Mitchell & Aziz, 2004)

As one can see, it is fairly straightforward to set up ELMAH, just having two steps. In addition its simple deployment and reusability is credited to it being componentized using HTTP modules and Handlers.

Enabling and Configuring Error Logging

ELMAH works on top of HTTP modules and HTTP handlers to provide its functionality, as the name suggests.  Using HTTP handlers capable of formatting errors and their details in several formats, ELMAH is able to report to its end-users valuable data regarding exceptions.

Error logging is achieved by intercepting uncaught exceptions at the application level and logging them into a persistence store, using an HTTP module called ErrorLogModule. In order to enable this functionality, the ErrorLogModule needs to be declared in the httpModules node of the Web.config file. As displayed below.

1.<system.web>

2.  <httpModules>

3.    <add name=”ErrorLog” type=”Elmah.ErrorLogModule, Elmah” />

4.  </httpModules>

5.</system.web>

ELMAH comes standard with four error log providers, which are listed in the table below.

ErrorLog implementation Description Medium Trust (2.0 only) 1.x 2.0
MemoryErrorLog Logs errors in RAM. Yes Yes Yes
XmlFileErrorLog Logs errors in multiple XML files. Yes Yes Yes
SQLiteErrorLog Logs errors in SQLite. No No Yes
SqlErrorLog Logs errors in Microsoft SQL Server. Yes Yes Yes

Conclusion

In summation, above I have described the most basic functionality of ELMAH and how it may be setup. ELMAH provides a pluggable logging and notification system equipped with many useful additional features for monitoring ASP.NET applications. To learn more about ELMAH and details on the features it provides please visit the links provided.

Links

Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components

http://msdn.microsoft.com/en-us/library/aa479332.aspx

ELMAH – Error Logging Modules And Handlers

http://dotnetslackers.com/articles/aspnet/ErrorLoggingModulesAndHandlers.aspx

Works Cited

Mitchell, S., & Aziz, A. (2004, September). Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components. Retrieved 1 10, 2011, from msdn: http://msdn.microsoft.com/en-us/library/aa479332.aspx

Tags: ASP.NET,

1 Comment. Leave new

Regarding setting up; using nuget in VS2010 you could simply do “Install-Package elmah”. Problem solved :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>