很简单的文件追加程序日志记录不工作 [英] Very simple file appender logging not working
问题描述
下面是我的web.config信息:
Here's my web.config information:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<root>
<level value="ALL" />
</root>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="c:\temp\log-file.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
</log4net>
...
这里的code,它初始化记录器:
Here's the code that initializes the logger:
protected void SendMessage()
{
log4net.Config.XmlConfigurator.Configure();
ILog log = LogManager.GetLogger(typeof(Contact));
...
log.Info("here we go!");
log.Debug("debug afasf");
...
}
它不工作,无论我似乎做。我正确地引用了log4net.dll,并通过调试应用程序,我可以看到日志对象得到正确的初始化。这是一个asp.net 3.5框架的Web项目。任何意见/建议吗?
It doesn't work, no matter what I seem to do. I am referencing the 'log4net.dll' correctly, and by debugging the application I can see that the log object is getting initiated properly. This is an asp.net 3.5 framework web project. Any ideas/suggestions?
我原以为这个错误可能是由于一个文件的写权限的限制,但是这似乎并没有出现这种情况(或因此我认为)。
I thought originally this error may be due to a file write permission constraint, but that doesn't seem to be the case (or so I think).
推荐答案
我找到了答案:我需要requirePermission =false的标签在我的web.config配置seciton
I found the answer: I needed the requirePermission="false" tag in my web.config's configuration seciton.
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" **requirePermission="false"**/>
</configSections>
这篇关于很简单的文件追加程序日志记录不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!