log4net smtp附加程序未发送电子邮件 [英] log4net smtp appender not sending emails

查看:191
本文介绍了log4net smtp附加程序未发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现log4net来发送电子邮件.
以下是我的代码,但未发送电子邮件.

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>

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

AssemblyInfo.cs中的

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

此配置对于文件输出(即RollingFileAppender)工作正常,但不适用于SmtpAppender.

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

推荐答案

我正在使用与Gmail SMTP邮件非常类似的附加程序,但在我的情况下,我使用了不同的端口:

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

<port value="587"/>

所有其他设置都相同,因此请尝试一下,看看它是否对您有用.这是Gmail用于TLS的端口,此处引用.

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.

这篇关于log4net smtp附加程序未发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆