Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Log4net SMTPAppender send email Asynchronously?

Does the Log4net SMTPAppender send email asynchronously? If it doesn't, how can I send logging emails asynchronously?

My log4net.config is:

<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>
  <log4net>
    <appender name="SMTPAppender" type="log4net.Appender.SMTPAppender">
      <authentication value="Basic" />
      <to value="[email protected]" />
      <from value="[email protected]" />
      <username value="[email protected]" />
      <password value="yyy" />
      <subject value="xxx" />
      <smtpHost value="smtp.xx.com" />
      <lossy value="true" />
      <evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="WARN" />
      </evaluator>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline%date [%thread] %-5level %logger %newline %message%newline%newline%newline" />
      </layout>
    </appender>
    <root>
      <level value="INFO"></level>
    </root>
    <logger name="MyLogger">
      <level value="INFO"></level>
      <appender-ref ref="SMTPAppender"></appender-ref>
    </logger>
  </log4net>
</configuration>
like image 820
artwl Avatar asked Aug 24 '11 06:08

artwl


People also ask

Why log4net is used?

log4net is a tool to help the programmer output log statements to a variety of output targets. In case of problems with an application, it is helpful to enable logging so that the problem can be located. With log4net it is possible to enable logging at runtime without modifying the application binary.

What is log4net in API?

log4net is still one of the most commonly used logging frameworks for . NET. While originally being a port of the log4j logging framework for Java, a lot has happened over the years, to make log4net a unique logging option for . NET/C# developers.

Does log4net create directory?

Log4net watches for any new file created in the folder so simply creating the . log4net configuration file triggers the update within the component that is logging. When using a file appender, the destination folder does not have to exist. Log4net creates the folder.


1 Answers

You could just call the logging method asynchronously like this:

Task.Factory.StartNew(() => log.Info("Message I want to email"));

I actually got this suggestion from the following SO article:

How do I create an asynchronous wrapper for log4net?

like image 69
Cole W Avatar answered Oct 23 '22 04:10

Cole W