Saturday, June 10, 2006

A simple walkthrough of ELMAH

A few well known developers / authors in the .NET community, Atif Aziz and Scott Mitchell, have released a useful error logging utility demonstrating the power of HTTP Modules and HTTP Handlers in ASP.NET. Here's my attempt to oversimplify the process of adding their utility to an existing ASP.NET Web site.
  1. Download the latest installation from the ELMAH gotdotnet workspace
  2. After installing the MSI, add a reference to the GotDotNet.Elmah.dll usually located in the GotDotNet\ELMAH\1.0\bin folder under Program Files. Or, if you had the assembly installed into the GAC then skip this step.
  3. Download the Error Mail Module Extension also from the ELMAH gotdotnet workspace. Add a reference to this the ErrorMailModuleExtension.dll as well.
  4. Edit the web.config and add the following 4 sections: First section goes after the configuration tag at the top <configSections> <!-- Allows for a new section group to the Web.config --> <sectionGroup name="gotdotnet.elmah"> <!-- Indicates that inside the section group there will be anerrorLog section --> <section name="errorLog" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> <section name="errorMail" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> </sectionGroup> </configSections> Second section goes just before system.web section

    <gotdotnet.elmah> <errorMail from=yoursender@yourdomain.com to=youruser@yourdomain.com smtpServer="yoursmtpserver.yourdomain.com"/> <errorLog type="GotDotNet.Elmah.MemoryErrorLog, GotDotNet.Elmah, Version=1.0.5527.0, Culture=neutral, PublicKeyToken=978d5e1bd64b33e5" /> </gotdotnet.elmah> Third and fourth sections go within the system.web section <httpHandlers> <add verb="POST,GET,HEAD" path="elmah/default.aspx" type="GotDotNet.Elmah.ErrorLogPageFactory, GotDotNet.Elmah, Version=1.0.5527.0,Culture=neutral, PublicKeyToken=978d5e1bd64b33e5"/> </httpHandlers>

    <!-- Adds the ErrorLogModule HTTP Module to the HTTP pipeline. --> <httpModules> <add name="ErrorLog" type="GotDotNet.Elmah.ErrorLogModule, GotDotNet.Elmah, Version=1.0.5527.0, Culture=neutral, PublicKeyToken=978d5e1bd64b33e5"/> <add name="ErrorMail" type="GotDotNet.Elmah.ErrorMailModuleExtension, ErrorMailModuleExtension"/> </httpModules>

  5. Make sure to edit the gotdotnet.elmah section and enter in your own details within the errorMail tag.

  6. Test the system by going to /elmah/default.aspx off the root of your application (http://yourserver/yourapproot/elmah/default.aspx) If that comes up, you can create a test error by adding a /test to the end of the URL, as in: http://yourserver/yourapproot/elmah/default.aspx/test

  7. If you run into any trouble, check the gotdotnet workspace. There’s a great technical doc that goes into this in much greater detail.

No comments: