0

ELMAH - a benefit to every asp.net website

by Jeremy 4. February 2010 11:33

ELMAH is an open-source .Net dll that allows for simple, pluggable exception notification and logging.  It takes all unhandled exceptions and allows the developer to configure notifications and/or logging of those exceptions.  There are many different configuration options, including where to log (in memory, database, text file, etc), and how to notify (email, twitter, etc.).  The configuration below assumes a common scenario of sending an email and logging to sql server when an unhandled exception occurs.

Steps for setup:

  1. Download the latest zip file (includes dll and documentation) http://code.google.com/p/elmah/
  2. Reference the dll from your website
  3. Run the included database script (located in the "db" folder of the downloaded zip) on the database where you would like to log exceptions
  4. Modify the config (assumes II6, see documentation on elmah site for IIS7)

<sectionGroup name="elmah">
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
    </sectionGroup>
    
    <httpHandlers>
      <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    </httpHandlers>
    
    <httpModules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
    </httpModules>

    <elmah>
        <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="configuredConnectionString" />
        <errorMail from="fromEmail" to="developerEmail" cc="ccEmail" subject="emailSubject" smtpServer="smtpServerIP" />
    </elmah>

 

See sample web.configs: http://elmah.googlecode.com/svn/tags/REL-1.0/samples/web.config 

How to view logged exceptions:
http://website/elmah.axd

How to throw a test exception:
http://website/elmah.axd/test

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | Exception Handling

Powered by BlogEngine.NET 1.4.5.0
Original Design by Laptop Geek, Adapted by onesoft