这是我的 web.config 信息:
<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>
...
这是初始化记录器的代码:
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项目。有什么想法/建议吗?
我最初认为这个错误可能是由于文件写入权限限制造成的,但事实似乎并非如此(或者我认为是这样)。
我找到了答案:我需要在 web.config 的配置部分中使用 requirePermission="false" 标签。
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" **requirePermission="false"**/>
</configSections>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)