Log4Net 多个 SMTP 附加程序?
我已经配置了 SMTP 附加程序,以便在出现错误时发送电子邮件。
<appender name="EmailAppender">
<bufferSize value="50" />
<lossy value="false" />
<threshold value="ALL" />
<evaluator type="log4net.Core.LevelEvaluator,log4net">
<threshold value="ERROR" />
</evaluator>
</appender>
当操作(不是错误)完成时,我还需要收到一封电子邮件。理论上我可以将其记录为错误并收到电子邮件,但实际上这不是错误,而是表明操作已完成(更像是信息)。
我应该添加另一个 SMTP 附加程序吗?
I have configured a SMTP appender to send an email whenever there's an error.
<appender name="EmailAppender">
<bufferSize value="50" />
<lossy value="false" />
<threshold value="ALL" />
<evaluator type="log4net.Core.LevelEvaluator,log4net">
<threshold value="ERROR" />
</evaluator>
</appender>
I need to also get an email when an operation (which is not an error) is completed. I can in theory log this as an error and get an email but in reality it's not an error but an indication that an operation has been completed (More like an INFO).
Should I add another SMTP appender?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够将
更改为
。然后,此附加程序将发送有关 INFO、WARN、ERROR 和 FATAL 的电子邮件。如果您需要自定义级别,可以使用类似的内容:
请参阅此问题了解有关如何使用自定义级别进行过滤的更多信息。 Apache 在此处提供了有关级别的更多信息。
You should be able to change
<threshold value="ERROR"/>
to<threshold value="INFO"/>
. This appender will then deliver emails for INFO, WARN, ERROR and FATAL.If you need a custom level, you can use something like:
See this question for more information on how to filter with custom levels. Apache provides more information on levels here.
在我的一个项目中,我使用命名空间来控制日志记录。这是示例配置:
根据源类的命名空间,您可以调整日志记录级别。因此,在上面的示例中,我仅记录来自 NHibernate 的警告和来自 MyNameSpace.MyBusinessCore 的所有内容(包括 DEBUG 和 TRACE)。
总而言之,在您的示例中我只会添加以下内容:
Than Your.Namespace 还将发送 INFO 级别日志。
In one of my projects I use namespaces to control logging. Here's sample configuration:
Depending on the namespace of the source class, you can adjust the logging level. Thus in the sample above I log only WARNings from NHibernate and everything from MyNameSpace.MyBusinessCore (including DEBUG and TRACE).
To sum up, in your example I would only add the following:
Than Your.Namespace will also send INFO level logs.