Nlog 在一天中的特定时间发送电子邮件警报



有没有办法过滤Nlog以仅在一天中的特定时间发送电子邮件警报(例如,周一至周五上午8点至晚上7点(?

它是一个控制台应用程序,配置为使用 TopShelf 用作 Windows 服务。

你可以为此使用过滤器。像这样:

<logger name="*" writeTo="myMailTarget">
<filters defaultAction='Log'>
<when condition="${date:format=H} >= 20" action="Ignore" />
<when condition="${date:format=H} <= 6" action="Ignore" />
</filters>
</logger> 

https://github.com/nlog/NLog/wiki/Filtering-log-messages 和 https://github.com/NLog/NLog/wiki/Date-Layout-Renderer

最新更新