C# 无法识别的配置部分 log4net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19419540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unrecognized configuration section log4net
提问by Shreyas Achar
I have this code in web.config:
我在 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>
And I have downloaded log4net.dll
and placed it in Bin
Folder.
我已经下载log4net.dll
并把它放在Bin
文件夹中。
In one of My aspx.cs
pages I have added this code:
在我的其中一个aspx.cs
页面中,我添加了以下代码:
using log4net;
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
But it's giving error as Unrecognized configuration section log4net
.
但它给出的错误为Unrecognized configuration section log4net
.
采纳答案by Darin Dimitrov
You need to declare the log4net
section:
您需要声明该log4net
部分:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
Take a closer look at the documentation
which explains the necessary things to do.
仔细查看documentation
解释了必须要做的事情的 。
回答by lambex
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
</configuration>
add to your app.config file
添加到您的 app.config 文件