C# Collect all Errors and send one Email when Programm is finished using log4net

83 views Asked by At

Is there a way to collect all exceptions with the level value Error and combine them into one E-Mail? Currently I will get one E-Mail for each Log.Error(ex) in my programm.

Edit: I know that the bufferSize with value one, will cause to send the mail if Log.Error is called. But raising it up, causes send all logging events(info...) in the same mails as the Error.

My Log4Net Config:

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
    <to value="[email protected]" />
    <from value="[email protected]" />
    <subject value="oops there is an error" />
    <smtpHost value="[email protected]" />
    <port value="25" />
    <bufferSize value="1" />
    <lossy value="true" />
    <evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="ERROR" />
    </evaluator>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline%newline%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
    </layout>
</appender>
1

There are 1 answers

0
jeanluc162 On BEST ANSWER

Using a filter instead of an evaluator

<filter type="log4net.Filter.LevelMatchFilter">
    <acceptOnMatch value="true" />
    <levelToMatch value="ERROR" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />

And upping the Buffer Size should solve your issue.