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:
-
Download the latest zip file (includes dll and documentation) http://code.google.com/p/elmah/
- Reference the dll from your website
- Run the included database script (located in the "db" folder of the downloaded zip) on the database where you would like to log exceptions
- 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