Mik*_*Del 17 .net c# logging 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" />
Run Code Online (Sandbox Code Playgroud)
这是我的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>
Run Code Online (Sandbox Code Playgroud)
我的配置有什么问题?
更新:
还有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>
Run Code Online (Sandbox Code Playgroud)
Web.Test.cofig - 与Release 1相同
和Web.Debug.config,它是空的:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
</configuration>
Run Code Online (Sandbox Code Playgroud)
Pet*_*ter 24
你在XmlConfigurator.Configure()某个地方打电话吗?
删除这些调用,只添加[assembly: log4net.Config.XmlConfigurator(Watch = true)]属性.
通常,在单独的文件中配置log4net更容易.创建文件log4net.config并将属性更改为:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]
Run Code Online (Sandbox Code Playgroud)
删除你的部分web.config.
定义下面的部分似乎没有错<configSections>.
尝试[assembly: log4net.Config.XmlConfigurator(Watch = true)]在项目的properties文件夹中添加AssemblyInfo.cs.如果您的配置在标记下正确,这应该可以解决问题.
编辑:
XmlElement log4NetSection = (XmlElement)ConfigurationManager.GetSection("log4net");
log4net.Config.XmlConfigurator.Configure(log4NetSection);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23334 次 |
| 最近记录: |