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

user1628194
  • 139
  • 3
  • 9

2 Answers2

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.

dan
  • 13,132
  • 3
  • 38
  • 49
  • 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? – user1628194 Oct 02 '12 at 20:23
  • Using a custom TriggeringEventEvaluator will allow you to send a custom email on a special log message content/level. – dan Oct 02 '12 at 20:26
  • 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. – user1628194 Oct 02 '12 at 21:19
  • 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? – user1628194 Oct 02 '12 at 22:44
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" />
Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73