这是我的错误信息:
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 - 与 Release one 相同
和 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
中的部分。
关于c# - log4net 配置 - 找不到部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17468841/