Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4net - smtp appender not working

Tags:

log4net

I am using log4net for sending mails when any app error occurs. I have configured the log4net but mail is not recd. Following is the config:

    <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
        <to value="[email protected]"/>
        <from value="[email protected]"/>
        <subject value="ERROR | MRM Application"/>
        <smtpHost value="relaymail.sapient.com"/>
        <bufferSize value="512"/>
        <lossy value="true"/>
        <evaluator type="log4net.Core.LevelEvaluator">
            <threshold value="ALL"/>
        </evaluator>
        <layout type="log4net.Layout.PatternLayout,log4net">
            <conversionPattern value="%property{log4net:HostName} :: %level :: %message %newlineLogger: %logger%newlineThread: %thread%newlineDate: %date%newlineNDC: %property{NDC}%newline%newline"/>
        </layout>
    </appender>

Is there any other changes that needs to be made?

like image 323
Ankit Avatar asked Feb 09 '10 12:02

Ankit


4 Answers

It looks good. To see some log4net debug messages in your console add the following lines in your app.config

  <appSettings>
    <add key="log4net.Internal.Debug" value="true"/>
  </appSettings>

Maybe this will give you a hint.

like image 98
Hans van Dodewaard Avatar answered Oct 27 '22 10:10

Hans van Dodewaard


Check if you need SMTP authentication.

Also bufferSize value="512" means it will collect 512 messages before sending an email. I'm pretty sure you don't want that.

like image 36
Mauricio Scheffer Avatar answered Oct 27 '22 11:10

Mauricio Scheffer


I also found out that the appender has to be referenced in the root element like such:

    <root>
      <level value="INFO"/>
      <appender-ref ref="LogFileAppender"/>
      <appender-ref ref="ConsoleAppender"/>
      <appender-ref ref="SmtpAppender"/>      
    </root>
  </log4net>
like image 6
M Akin Avatar answered Oct 27 '22 11:10

M Akin


<lossy value="false" />

it helped for me

like image 5
Yaplex Avatar answered Oct 27 '22 11:10

Yaplex