配置 NLog 以在一周中的设定日期记录

Configure NLog to log at set days of week

我有一项服务 运行 每小时使用 NLog 在发生异常时发送邮件。那么如何设置周六日不登录呢?我能做到吗?

这是我的目标:

<target name="m"
   xsi:type="Mail"
   html="true"
   smtpServer="*******"
   smtpPort="*******"
   smtpAuthentication="*******"
   smtpUserName="*******"
   smtpPassword="*******"
   enableSsl="true"
   subject="Exception"
   from="*******"
   to="*******"
   layout ="${longdate} ${uppercase:${level}}${newline} ${callsite:className=true:includeSourcePath=true:methodName=true}${newline} ${message}${newline}"
   useSystemNetMailSettings="false" />

和规则:

<logger name="*" minlevel="Fatal" writeTo="m" />

也许使用 PostFilteringWrapper,并使用如下过滤条件:

  • 不等于('${date:format=ddd}', 'Sat')
  • 不等于('${date:format=ddd}', 'Sun')

https://github.com/NLog/NLog/wiki/PostFilteringWrapper-target

https://github.com/NLog/NLog/wiki/When-filter

https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-extract-the-day-of-the-week-from-a-specific-date