c# – log4net配置 – 找不到节

前端之家收集整理的这篇文章主要介绍了c# – log4net配置 – 找不到节前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的错误信息:
log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

这是我的web.config:

<?xml version="1.0"?>
<configuration>
    <configSections>
       <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
    </configSections>

   <system.serviceModel>
   ...
   </system.serviceModel>

   <connectionStrings>
   ...
   </connectionStrings>

   <log4net>
   ...
   </log4net>

</configuration>

我的配置有什么问题?

更新:

还有Web.Release.config:

<?xml version="1.0"?>    
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

    <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
    </system.web>

    <system.serviceModel>
    ...
    </system.serviceModel>

    <connectionStrings>
    ...
    </connectionStrings>

    <log4net>
    ...   
       <root>
          <level value="DEBUG" xdt:Transform ="Replace"/>
       </root>
    </log4net>

</configuration>

Web.Test.cofig – 与发行版一样

和Web.Debug.config,这是空的:

<?xml version="1.0"?>

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">    

</configuration>

解决方法

你在某处调用XmlConfigurator.Configure()

删除这些调用,只添加[assembly:log4net.Config.XmlConfigurator(Watch = true)]属性.

通常在单独的文件中配置log4net是比较容易的.创建一个文件log4net.config并将您的属性更改为:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config",Watch = true)]

删除您的web.config中的部分.

原文链接:https://www.f2er.com/csharp/94864.html

猜你在找的C#相关文章