Search code examples
c#asp.net-mvc-5elmaherror-loggingelmah.mvc

Turn off emails only for 404 Errors


I am sharing a simple solution for turning off Elmah sending emails for 404 Http Errors. I wanted elmah to still log the 404 errors in case we find some hackers trying to find some config files etc.


Solution

  • You need to add the following to your Web.config file:

    system.web node:

    <httpModules>
        ...
        <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
        <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
        ...
    </httpModules>
    

    configSections node:

    <sectionGroup name="elmah">
        <section name="errorFilter" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
    </sectionGroup>
    

    elmah node:

    <errorFilter>
        <test>
            <and>
                <equal binding="HttpStatusCode" value="404" type="Int32" />
                <regex binding="FilterSourceType.Name" pattern="mail" />
            </and>
        </test>
    </errorFilter>