【问题标题】:Send email alerts from Nlog for specific exceptions从 Nlog 发送电子邮件警报以了解特定异常
【发布时间】:2018-10-17 15:34:11
【问题描述】:

我正在配置NLog 配置,该配置非常适合登录文本文件。现在最重要的是,我想将条件目标设置为Mail,它应该只针对一组特定的异常被触发。例如 - 如果有 PaymentFailedException、CardExpiredException,那么 NLog 应该以 Mail 为目标。 我已经检查了NLog 文档,但我找不到任何方法来为特定的异常集设置它。但是,NLog 允许将目标设置为 Mail 用于异常级别。

【问题讨论】:

    标签: email nlog alerts


    【解决方案1】:

    您可以为此配置使用<when>。

    例如

    <logger name="*" writeTo="myMailTarget">
      <filters>
        <when condition="not contains('${exception:format=type}', 'PaymentFailedException") action="Ignore" />
      </filters>
    </logger> 
    

    见filtering log messages和&lt;when&gt; docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-24
      • 2020-11-09
      • 1970-01-01
      • 2021-11-11
      • 2021-08-18
      • 1970-01-01
      • 2021-04-25
      • 2017-10-14
      相关资源
      最近更新 更多