配置NLog以每周的设定日期记录

时间:2017-09-15 14:20:01

标签: c# nlog

我有一个每小时运行一次的服务,在发生异常时使用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" />

1 个答案:

答案 0 :(得分:1)

也许使用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