【问题标题】:ELMAH: Only sending specific exception type via mailELMAH:仅通过邮件发送特定的异常类型
【发布时间】:2010-05-31 08:34:08
【问题描述】:

我为 Web 应用设置了 ELMAH,将异常记录到 SQL 服务器。

我也希望 ELMAH 给我发一封电子邮件,但仅限于抛出特定异常时(即。MySpecialException)。

ELMAH 仍必须将所有异常记录到 SQL 服务器。

我知道您可以在 global.asax 中以编程方式执行此操作,但我更喜欢使用 web.config。

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

更新

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

<test>
    <and>
        <not>
            <is-type binding="Exception" type="MyApp.MySpecialException" />
        </not>
        <regex binding="FilterSourceType.Name" pattern="mail" caseSensitive="false"/>
    </and>
</test>

【问题讨论】:

    标签: c# asp.net elmah


    【解决方案1】:

    当然可以。查看elmah 的过滤文档。

    特别是查看“按来源过滤”部分

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

    【讨论】:

    • 看过文档。恐怕我需要更多的帮助。我被困在这个: .. 这不起作用.
    • 这可能有多种原因。您是否已将 ErrorFilterModule 添加到 HttpModules 中?将所有 elmah 配置添加到您的帖子中可能是一个想法。
    • 这个问题也可能有帮助。 stackoverflow.com/questions/1788900/…
    猜你喜欢
    • 1970-01-01
    • 2012-01-21
    • 2012-03-30
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 2015-02-02
    • 1970-01-01
    相关资源
    最近更新 更多