log4j SMTPAppender - Email multiple error messages
Asked Answered
S

2

6

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.

I have seen the bufferSize variable but that appears to be for all types of message, not just ERRORS.

Does anyone know how I might achieve this?

Thanks

Stealing answered 2/10, 2012 at 18:51 Comment(0)
O
0

You can use: log4j.appender.myMail.evaluatorClass to implement the TriggeringEventEvaluator, this way you can programmatically decide when/what messages to send. See: http://www.manning-sandbox.com/thread.jspa?threadID=9913 for more details.

Orgasm answered 2/10, 2012 at 18:56 Comment(4)
I see the example there which works to send all messages, but I would only like to send ERROR and above, and also aggregate them into a single email. If possible could I send a signal from my program to send the email?Stealing
Using a custom TriggeringEventEvaluator will allow you to send a custom email on a special log message content/level.Orgasm
I have managed to implement this now... I set a variable at the beginning of my program to false, and then true when the program finishes. This variable is checked in isTriggeringEvent()... the issue is that I need to write my own error after setting the variable to true just to trigger a check of isTriggeringEvent(). Is there another way for me to fire the email off? It would be good if I could replace that error message with an info message.Stealing
In other terms... what I need is something that could call SMTPAppender.sendBuffer()... which is a protected method, from my program. So is there any equivalent, other than sending out another error to trigger this?Stealing
B
0

Try adding/using an Evaluator e.g. 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 value="true" />
<bufferSize value="xxxx" />
Bloemfontein answered 2/10, 2012 at 19:8 Comment(1)
I have just tried this, but I still get one email for each error that occurs.Stealing

© 2022 - 2024 — McMap. All rights reserved.