1

I would like to send an email only after 100 ERRORS were written as a html table(That's the purpose of the SmtpExtendedAppender, iterate over all the messages that were saved) but I am not sure how to access them.

This is my app.config:

<appender name="SmtpAppender" type="log4net.Appender.SmtpExtendedAppender">
        <authentication value="Basic" />
        <password value="xxxxxx"/>
        <username value="xxxxxxxx"/>
        <from value="myemail@gmail.com" />
        <to value="toemail@gmail.com" />
        <smtpHost value="smtp.gmail.com" />
        <isBodyHtml value="true" />
        <bufferSize value="100" />
        <EnableSsl value="true"/>
        <subject value="test logging message" />
        <lossy value="true" />
        <evaluator type="log4net.Core.LevelEvaluator">
            <threshold value="WARN"/>
        </evaluator>
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date{ABSOLUTE} [%logger]%newlineUsername: %property{username}%newline%level - %message%newline%exception" />
        </layout>
    </appender>

This is my console application:

static void Main(string[] args)
        {
            Console.WriteLine("hello world");

            log.Error("This is my first error message");

            log.Error("This is my second error message");

            Console.ReadLine();
        }

I am not fully understand how the log4net buffer size works, even though I gave it a value of 100, it sends me 2 separated emails every time I run my console application.

If I will run this application 50 times to get to 100 ERRORS, would it be possible to accumulate them and then send them in one email?

Offir
  • 3,252
  • 3
  • 41
  • 73
  • I don't think so - when the app exits, the appender closes, flushes it's buffer and so the emails are sent. You would need to extend the appender to have some kind of backing storage to preserve the log events until the threshold is reached. – stuartd Mar 29 '17 at 09:29
  • @stuartd you mean like store the messages in `cache` or `session`? – Offir Mar 29 '17 at 09:38
  • Unless you're prepared to lose messages, you would want to use persistent storage. – stuartd Mar 29 '17 at 09:40
  • @stuartd In this answer he says the buffer messages are saved in the RAM , http://stackoverflow.com/questions/30630952/log4net-buffer-size-not-working/30631155#30631155 Is that true? – Offir Mar 29 '17 at 13:49
  • 1
    While the process (ie your console app is running) the messages are buffered in the process memory. When the process ends (the app terminates) whatever is in the buffer is flushed. – stuartd Mar 29 '17 at 13:56

1 Answers1

2

No that is not possible. The appender works not over multiple instances of your application. Every time you restart your application, all buffers are empty.

Peter
  • 27,590
  • 8
  • 64
  • 84