在单独的电子邮件中发送日志

时间:2015-02-20 12:59:29

标签: nlog

使用内置nlog Mail target时,我收到多个错误日志,这些日志分组为一封电子邮件。似乎有某种缓冲发生。

我希望每个日志都单独发送。

我的log.config文件示例:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <targets async="true">
   <target
      xsi:type="Mail"
      name="email"
      subject="MyProject [${level:uppercase=true}]: ${message}"
      body="${message}"
      useSystemNetMailSettings="True"
      html="True"
      addNewLines="True"
      replaceNewlineWithBrTagInHtml="True"
      to="xyz@mydomain.co.za"
      from="no-reply@mydomain.co.za"/>
  </targets>
  <rules>
    <logger name="*" level="Error" writeTo="email" />
  </rules>
</nlog>

我该怎么做?

1 个答案:

答案 0 :(得分:1)

很抱歉,默认情况下这是不可能的,您可以通过以下链接验证:https://github.com/NLog/NLog/blob/master/src/NLog/Targets/MailTarget.cs#L282-L289

但是你总是可以根据MailTarget创建自己的NLog目标https://github.com/nlog/nlog/wiki/How-to-write-a-Target