可能是一个非常简单的设置,但我尝试了设置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);
}
有什么问题吗?