我对 log4net 有以下 SmtpAppender 配置:
<appender name="AlchemySmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="my@mail.com" />
<from value="validfrom@mail.com" />
<subject value="Fatal error on Web Portal" />
<smtpHost value="ValidHost" />
<username value="myUserName"/>
<password value="myPassword"/>
<lossy value="false" />
<bufferSize value="0"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger - %message%newline%newline%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="AlchemySmtpAppender" />
</root>
电子邮件从不发送。
我启用了内部调试并检查了跟踪/输出并发现以下内容:
log4net: Loading Appender [SmtpAppender] type: [log4net.Appender.SmtpAppender]
log4net: Setting Property [To] to String value [my@mail.com]
log4net: Setting Property [From] to String value [validfrom@mail.com]
log4net: Setting Property [Subject] to String value [Fatal error on Web Portal]
log4net: Setting Property [SmtpHost] to String value [ValidHost]
log4net: Setting Property [Username] to String value [myUserName]
log4net: Setting Property [Password] to String value [myPassword]
log4net: Setting Property [Lossy] to Boolean value [False]
log4net: Setting Property [BufferSize] to Int32 value [0]
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 [%newline%date [%thread] %-5level %logger - %message%newline%newline%newline]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [thread] 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=5,max=2147483647,leftAlign=True]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [logger] 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 [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: reated Appender [SmtpAppender]
log4net: Adding appender named [SmtpAppender] to logger [root].
log4net: Hierarchy Threshold []
我看不到任何错误,也没有电子邮件。电子邮件地址、凭据和主机都是有效的,因为我们也在 web.config 文件的 System.Net 部分中使用它们并且它们运行良好。
任何人都知道我的配置可能做错了什么?或者也许我可以做一些其他形式的故障排除来解决这个问题?
使用 RollingFile、Trace 和 AdoNetAppender 等其他附加程序也可以正常工作。