带Gmail的Log4Net SMTP Appender

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带Gmail的Log4Net SMTP Appender相关的知识,希望对你有一定的参考价值。

我正在使用此代码。虽然我启用了Log4Net调试,但它没有错误。我也没有收到电子邮件。有任何想法吗?

我替换了登录凭据,并使用占位符替换了/。

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
      <authentication value="Basic" />
      <to value="to" />
      <from value="from" />
      <subject value="Log message" />
      <username value="myusername" />
      <password value="mypass" />
      <smtpHost value="smtp.gmail.com" />
      <port value="587"/>
      <bufferSize value="1" />
      <EnableSsl value="true"/>
      <lossy value="true" />
      <threshold value="FATAL"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date{ABSOLUTE} [%logger]%newlineUsername: %property{username}%newline%level - %message%newline%exception" />
      </layout>
</appender>
答案

我知道它已经晚了但是更换了

 <threshold value="FATAL"/>

<evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="ERROR" />
      </evaluator>
另一答案

我建议将以下内容放入appSettings节点。

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

然后它将输出诊断信息,例如

log4net: Setting Property [From] to String value [tomas@kodi.is]
log4net: Setting Property [Subject] to String value [Kodiak OMS Shortcode service]
log4net: Setting Property [SmtpHost] to String value [mail.sip.is]
log4net: Setting Property [Port] to Int32 value [25]
log4net: Setting Property [BufferSize] to Int32 value [1]
log4net: Setting Property [EnableSsl] to Boolean value [True]
log4net: Setting Property [Threshold] to Level value [DEBUG]
log4net: Setting Property [Lossy] to Boolean value [False]
log4net: Converter [message] Option [] Format  [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%utcdate [%level] - %message%newline%exception]
log4net: Converter [utcdate] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [] - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [exception] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: Created Appender [EmailLog]
log4net: Adding appender named [EmailLog] to logger [EmailLogger].
log4net: Hierarchy Threshold []
log4net:ERROR [SmtpAppender] ErrorCode: GenericFailure. Error occurred while sending e-mail notification.
System.Net.Mail.SmtpException: Server does not support secure connections.
   at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
   at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
   at System.Net.Mail.SmtpClient.GetConnection()
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at log4net.Appender.SmtpAppender.SendEmail(String messageBody)
   at log4net.Appender.SmtpAppender.SendBuffer(LoggingEvent[] events)

以上是关于带Gmail的Log4Net SMTP Appender的主要内容,如果未能解决你的问题,请参考以下文章

apache_conf [gmail SMTP info]用于配置外发电子邮件的smtp信息#gmail #smtp #notifications

无法通过 telnet 使用 smtp.gmail.com

为啥编码标头内容类型:text/html;在 Outlook 插件中使用 MailItem 时缺少 GMAIL 的 SMTP 服务器:SMTP.GMAIL.COM?

SMTP使用Gmail发送电子邮件问题

Spring Boot - 无法连接到 SMTP 主机:smtp.gmail.com,端口:25,响应:421

csharp 用C#编写的简单SMTP邮件客户端助手类,用于异步发送电子邮件。注意:使用Log4Net进行日志记录。