Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net smtp appender not sending emails

I'm trying to implement log4net to send email.
The following is my code but it's not sending emails.

 <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="...." />
  <from value="..." />
  <subject value="Logging Message" />
  <smtpHost value="smtp.gmail.com" />
  <port value="465"/>
  <authentication value="Basic" />
  <username value="..."/>
  <password value="..."/>
  <EnableSsl value="true" />
  <bufferSize value="1" />
  <lossy value="true" />
  <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="WARN"/>
  </evaluator>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %level %logger - %message%newline%exception" />
  </layout>
</appender>

and

<root>
  <level value="WARN" />
  <appender-ref ref="SmtpAppender" />
</root>

in the AssemblyInfo.cs

 [assembly: log4net.Config.XmlConfiguratorAttribute(Watch = true)]

and that's how I create the log object

  private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

This configuration is working fine for file output i.e. RollingFileAppender but not for SmtpAppender.

N i have tried many solutions from the internet but were not really helpful.

Please show me the right directions. thankx in advance :)

like image 537
Agnes Simpson Avatar asked Mar 20 '13 12:03

Agnes Simpson


1 Answers

I'm using a very similar appender for SMTP messages to Gmail, but in my case I use a different port:

<port value="587"/>

All the other settings are the same, so give that a try and see if it works for you. It's the port Gmail uses for TLS, referenced here.

like image 150
David Avatar answered Oct 25 '22 14:10

David