How to configure log4net SmtpAppender only to send me emails when I got to some level?

I am trying to configure SmtpAppender log4net to only receive email if a certain level of log has been reached, but with the last 10 lines from all levels. This is my configuration:

<appender name="EmailAppender" type="SmtpSubjectLayoutAppender">

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

  <bufferSize value="10" />
  <lossy value="false" />

  ...
</appender>

I am doing this with this code:

for (var i = 1; i <= 30; i++)
{
    logger.Info("This is just a test message " + i);
}

logger.Error("Error message");

The problem is that I get 3 emails, 2 with all the logs INFOand one that has the last few lines that happened before ERROR:

[2012-07-27 18:59:55.657][INFO ][Chase][tid=14972] This is just a test message 23
[2012-07-27 18:59:55.659][INFO ][Chase][tid=14972] This is just a test message 24
[2012-07-27 18:59:55.661][INFO ][Chase][tid=14972] This is just a test message 25
[2012-07-27 18:59:55.662][INFO ][Chase][tid=14972] This is just a test message 26
[2012-07-27 18:59:55.664][INFO ][Chase][tid=14972] This is just a test message 27
[2012-07-27 18:59:55.666][INFO ][Chase][tid=14972] This is just a test message 28
[2012-07-27 18:59:55.667][INFO ][Chase][tid=14972] This is just a test message 29
[2012-07-27 18:59:55.670][INFO ][Chase][tid=14972] This is just a test message 30
[2012-07-27 18:59:55.671][ERROR][Chase][tid=14972] Error message

How to configure the application to receive an email with the last 10 lines if WARN or higher has occurred, but otherwise ignore the buffer?

+5
source share
3

lossy true:

<lossy value="true" />

log4net , . log4net, , .

+4

<threshold value="WARN"/>

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

, (log4net version 1.2.13.0) ...

<lossy value="true" />

, .

+2

I would try:

How to filter at user level in log4net?

Filtering works well for me in other scenarios.

0
source

All Articles