Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
803 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...