log4net的不写入日志文件 [英] Log4net does not write the log file
本文介绍了log4net的不写入日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用log4net的一个简单的场景,但似乎我的追加程序不工作,因为消息不添加到日志文件。
I created a simple scenario using Log4net, but it seems that my appenders do not work because the messages are not added to the logfile.
我增加了以下到web.config文件:
I added the following to the web.config file:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
</configSections>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="D:\MyData\Desktop\LogFile.txt" />
<appendToFile value="true" />
<encoding value="utf-8" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
<root>
<level value="INFO" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
在全球ASAX文件,我说:
Within the global ASAX file I added:
ILog logger = LogManager.GetLogger(typeof(MvcApplication));
和Application_Start方法中中:
and within the Application_Start method:
logger.Info("Starting the application...");
我做了什么错?
What did I do wrong?
在此先感谢 约翰内斯
推荐答案
你叫
log4net.Config.XmlConfigurator.Configure();
在某处,使log4net的看你的配置?例如。在Global.asax中:
somewhere to make log4net read your configuration? E.g. in Global.asax:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
// Initialize log4net.
log4net.Config.XmlConfigurator.Configure();
}
这篇关于log4net的不写入日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文