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

Send logs in separate emails

当使用内置 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>

我该怎么做?

抱歉,默认情况下这是不可能的,您可以通过link验证: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