配置NLog在设置的星期几登录

问题描述:

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

您希望该服务运行,但不记录任何东西?为什么? – Amy

+0

我想要正常的日志,但没有电子邮件(我有2个目标)。我还设置它发送到5个不同的电子邮件。这意味着如果每次崩溃都会发送超过300封电子邮件。 –

+0

在我看来,正确的操作方法是修复应用程序,使其不会崩溃。 – Amy

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

  • 不等于($ {日期: '格式= ddd},'星期六')
  • 不等于($ {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