我正在使用此代码。虽然我启用了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>
答案 0 :(得分:0)
我知道现在已经晚了但是取而代之的
<threshold value="FATAL"/>
带
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ERROR" />
</evaluator>
答案 1 :(得分:0)
我建议将以下内容放入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)