Monday, February 7, 2011

Elmah - basic setup IIS 7 with MVC.Net

How to configure ELMAH.

  1. Copy elmah files to the bin folder
  2. Under section "configuration -> configSections" on your web.config, add these lines
    <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" />
     </sectionGroup>
  3. Under section "configuration" on your web.config, add these lines
    <elmah>
        <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
        <security allowRemoteAccess="1" />
    </elmah>
    
  4. Under section "configuration -> system.web" on your web.config, add these lines

    <httpHandlers>
          <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    </httpHandlers>
    <httpModules>
          <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
    </httpModules>
  5. If you are running IIS 7, under section "configuration -> system.webServer" on your web.config, add these lines


    <modules runAllManagedModulesForAllRequests="true">
          <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
    </modules>
    <handlers>
          <add name="elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    </handlers>
    
  6. If you are running MVC.Net, add this line of code to your register routes function on global.asax


    public static void RegisterRoutes(RouteCollection routes)
    {
       routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    }
    
  7. You are now ready to view the logs. Go to http://yoursitedomain.com/elmah.axd

No comments:

Post a Comment