简体   繁体   English

log4j SMTPAppender - 通过电子邮件发送多条错误消息

[英]log4j SMTPAppender - Email multiple error messages

I am using log4j's SMTPAppender to email me upon each exception, but I'd really prefer it to aggregate emails into one email with a batch of errors rather than one email for each error. 我正在使用log4j的SMTPAppender在每次例外时给我发电子邮件,但我真的更喜欢它将电子邮件聚合成一封电子邮件,其中包含一批错误,而不是每封错误发送一封电子邮件。

I have seen the bufferSize variable but that appears to be for all types of message, not just ERRORS. 我已经看到了bufferSize变量,但它似乎适用于所有类型的消息,而不仅仅是错误。

Does anyone know how I might achieve this? 有谁知道我怎么做到这一点?

Thanks 谢谢

You can use: log4j.appender.myMail.evaluatorClass to implement the TriggeringEventEvaluator , this way you can programmatically decide when/what messages to send. 您可以使用: log4j.appender.myMail.evaluatorClass来实现TriggeringEventEvaluator ,这样您就可以通过编程方式决定何时/什么消息要发送。 See: http://www.manning-sandbox.com/thread.jspa?threadID=9913 for more details. 有关详细信息,请参阅: http//www.manning-sandbox.com/thread.jspa?threadID = 9913。

Try adding/using an Evaluator eg below in the configuration: 尝试在配置中添加/使用评估器,例如:

<evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="ERROR"/>
</evaluator>

Also set lossy attribute to true along with the desired buffer size: 还将lossy属性设置为true以及所需的缓冲区大小:

<lossy value="true" />
<bufferSize value="xxxx" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM