我已经设置了默认的根记录器,并配置了RollingFileAppender和SmtpAppender。文件appender正常工作,但是SmtpAppender没有输出任何内容。
我是通过诊断按钮点击调用记录器的...
protected void btnReloadContractConfig_Click(object sender, EventArgs e)
{
// DIAGNOSTIC - Test email logger
log4net.ILog logger = log4net.LogManager.GetLogger("root");
logger.Error("btnReloadContractConfig_Click() - This is a TEST of delivery of error messages via email, triggered from the Admin.aspx.cs code file.");
}
...并且RollingFileAppender正在接收消息...
LOC=20120921-12:03:16.319,UTC=20120921-11:03:16.319,DELTA=10078,THR=6,ERROR,LOG=root,[(null)] - btnReloadContractConfig_Click() - 这是通过Admin.aspx.cs代码文件触发错误消息通过电子邮件传递的测试。
Log4Net的web.config条目在这里:
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
<appSettings>
<log4net
xsi:noNamespaceSchemaLocation="http://csharptest.net/downloads/schema/log4net.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="SmtpAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="MiniMkt01Log.txt"/>
<!-- <file value="${TMP}\log-file.txt" /> -->
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout" >
<header value="[Header] " />
<conversionPattern value="LOC=%date{yyyyMMdd-HH:mm:ss.fff},UTC=%utcdate{yyyyMMdd-HH:mm:ss.fff},DELTA=%timestamp,THR=%thread,%-5level,LOG=%logger,[%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="FacelessDevTeam@yahoo.com" />
<from value="hiblet@yahoo.com" />
<subject value="Logging Message" />
<smtpHost value="smtp.yahoo.com" />
<port value="25"/>
<authentication value="Basic" />
<username value="FacelessDevTeam@yahoo.com"/>
<password value="?????[real password hidden for obvious reasons]"/>
<!-- <EnableSsl value="true" /> -->
<bufferSize value="10" />
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="WARN"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<header value="[Header] " />
<!-- Previously... <conversionPattern value="%newline%date,%utcdate,%timestamp,[%thread],%-5level,%logger,[%property{NDC}] - %message%newline%newline%newline" /> -->
<conversionPattern value="%newlineLOC=%date{yyyyMMdd-HH:mm:ss.fff},UTC=%utcdate{yyyyMMdd-HH:mm:ss.fff},DELTA=%timestamp,THR=%thread,%-5level,LOG=%logger,[%property{NDC}] - %message%newline%newline%newline" />
</layout>
</appender>
</log4net>
在Application_Start()处理程序中,Global.asax文件正在被捕获web.config。
void Application_Start(object sender, EventArgs e)
{
// Start Log4Net, signal app has started
log4net.Config.XmlConfigurator.Configure();
log4net.ILog logger = log4net.LogManager.GetLogger("root");
logger.Info("Application_Start()");
}
管理员网页触发邮件似乎要么无限期挂起,要么瞬间挂起(半秒钟)然后继续。
开发环境不会因为异常而崩溃,要么挂起,要么在没有错误的情况下滑动。
- 如何从SmtpAppender中获取其他诊断信息?
- 我能独立测试端口/配置以检查出站编程电子邮件的本地阻止吗?
- log4net邮件是否保证已发送?如果将lossy=false,则会出现无限挂起这种情况,因为lossy属性和缓冲区大小非常敏感。
参考使用VS 2010、ASP.Net4和大量咖啡因。感谢您未来提供的任何帮助。