Logging Errors with ELMAH in ASP.NET MVC 3 – Part 1 – (Setup)

Tags: ASP.NET, MVC, Logging, Error Handler, Elmah

Add the ELMAH binary to the project

To install ELMAH using NuGet In Visual Studio 2010 (recommended), go to Tools >> Library Package Manager >> Add Library Package Reference… Select Online from the left search for Elmah and click Install.

Alternatively you can, download ELMAH from here and add a reference to the Elmah library.

Configure the ELMAH basics

Before we get all fancy, let’s just get it running. To do that, you need to merge the following changes into your web.config. NuGet should have made these additions already for you… but let’s double check it just in case.

<?xml version="1.0" encoding="utf-8"?>
    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    <security allowRemoteAccess="yes" />
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />

Also comment out this line from your Global.asax file as it interferes with ELMAH.

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    //filters.Add(new HandleErrorAttribute());

Note: The HandleErrorAttribute captures any unhandled errors and displays the Error view when custom errors are turned on. We’ll re-enable this later in this series when we further extend ELMAH, but for now, just comment it out.

Verify ELMAH is setup

You should now be able to run your project, go to /elmah.axd and see a report similar to this one...

Elmah Default Install

Well, that was all pretty simple. Just a little bit of Copypasta and you’ve got the basics of ELMAH up and running. This is confirmed to work on DiscountASP.net shared hosting environment.

Next Step: Logging Errors with ELMAH in ASP.NET MVC 3 – Part 2 – (Notifications) »

This Post is Part of a Multi-Part Series

Add a Comment