可能是一个非常简单的设置,但我尝试设置 Log4Net。在我的 web.config 中,我有:
<log4net>
<appender name="File" type="log4net.Appender.RollingFileAppender">
<file value="Logs\\Log4Net.log" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd-HHmm" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<logger name="File">
<level value="All" />
<appender-ref ref="LogFileAppender" />
</logger>
<root>
<level value="ALL"/>
<appender-ref ref="FileAppender"/>
</root>
</log4net>
我已将以下内容添加到我的配置部分:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
global.asax 中的以下内容:
log4net.Config.XmlConfigurator.Configure();
以下是我的 default.aspx:
ILog alog = log4net.LogManager.GetLogger(typeof(_Default));
log4net.ILog logger = log4net.LogManager.GetLogger("File");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetupSeo();
}
alog.Error("this test");
logger.Error("Front page loaded for ip " + Request.UserHostAddress);
}
怎么了?