ELMAH:仅通过邮件发送特定的异常类型

Sir*_*Lot 11 c# asp.net elmah

我让ELMAH设置了webapp,将异常记录到SQL服务器.

我希望ELMAH也向我发送电子邮件,但仅在抛出特定异常时(即MySpecialException).

ELMAH仍必须记录SQL Server的所有异常.

我知道你可以在global.asax中以编程方式进行,但我更喜欢使用web.config.

那么,如何使用web.config限制ELMAH错误邮件以过滤掉除特定异常类型之外的所有内容?

UPDATE

过滤器最终看起来像这样:

<test>
    <and>
        <not>
            <is-type binding="Exception" type="MyApp.MySpecialException" />
        </not>
        <regex binding="FilterSourceType.Name" pattern="mail" caseSensitive="false"/>
    </and>
</test>
Run Code Online (Sandbox Code Playgroud)

Joe*_*ham 7

它当然可以做到.查看elmah的过滤文档.

特别请查看按源过滤部分

<elmah>
...
<errorFilter>
    <test>
        <and>
            <equal binding="HttpStatusCode" value="404" type="Int32" />
            <regex binding="FilterSourceType.Name" pattern="mail" />
        </and>
    </test>
</errorFilter>
Run Code Online (Sandbox Code Playgroud)

  • 这个问题也可能有所帮助.http://stackoverflow.com/questions/1788900/filter-on-exception-text-in-elmah (3认同)