zoukankan      html  css  js  c++  java
  • 无法识别的配置节log4net的(Unrecognized configuration section log4net)

    每个配置文件中只允许存在一个 <configSections> 元素,并且,如果存在该元素,它还必须是根 <configuration> 元素的第一个子元素。

    问题:

    I have this code in 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.

    In one of My aspx.cs pages I have added this code:

    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.

    解决方案:

    You need to declare the log4net section:

    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    </configSections>

    Take a closer look at the documentation which explains the necessary things to do.

  • 相关阅读:
    WPF Web Application 客户端下载目录及有趣的搜索问题
    判断表是否存在
    C#获取存储过程返回值和输出参数值
    模态对话框刷新问题
    sql Server 导出数据到脚本
    使用.NET 2.0中的秒表-Stopwatch类进行速度测试 (转一个程序员的自省)
    使用Redirect打开新窗口
    弹出层
    windows7安装配置IIS7.5过程图解
    控制文本框输入
  • 原文地址:https://www.cnblogs.com/herizai/p/7206053.html
Copyright © 2011-2022 走看看