Filter exceptions logged in ELMAH

By default, all exceptions are logged in ELMAH's database. You can filter out exceptions and thus exclude them from the logs, for example, to exclude exceptions thrown from a certain IP range address. This address may correspond to your company's IP address and thus exclude logs made by your QAs or developers.

To filter and exclude exceptions from the log, you modify your application's web.config file. The following example demonstrates how to exclude from the logs all exceptions of type HttpStatusCode with value 404:

  1. Configure an additional Elmah.ErrorFilterModule module. Add the module after all other ELMAH logging modules:

    XML
    <httpModules>
      ...
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
      ...
    </httpModules>
  2. In the configSections section, add a dedicated configuration section with Elmah.ErrorFilterSectionHandler for the filtering assertions:

    XML
    <configSections>
      ...
      <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>
      ...
    </configSections>
  3. In the modules section, add the ErrorFilterModule:

    XML
    <modules>
      ...
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
      ...
    </modules>
  4. In the elmah group, add the <errorFilter> section:

    XML
    <elmah>
      ...
      <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah-sqlserver" />
      <errorFilter>
        <test>
          <equal binding="HttpStatusCode" value="404" type="Int32" />
        </test>
      </errorFilter>
    </elmah>
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?