无法识别的配置节 log4net
本文关键字:log4net 配置 识别 | 更新日期: 2023-09-27 18:35:47
我在web.config中有以下代码:
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="D:'logFileFaculty.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
</log4net>
我已经下载了log4net.dll
并将其放在Bin
文件夹中。
在我的aspx.cs
页面之一中,我添加了以下代码:
using log4net;
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
但它给出了错误,因为Unrecognized configuration section log4net
.
您需要
声明log4net
部分:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
仔细看看解释必要事情的documentation
。
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
</configuration>
添加到您的应用.config 文件
不知道为什么不发布整个示例。
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
...
<log4net>
...
</log4net>
</configuration>