log4net:错误XmlConfigurator:无法在应用程序的.config中找到配置节'log4net'

时间:2012-04-04 11:27:51

标签: c# log4net

我为日志记录创建了一个单独的控制台应用程序,然后将该单个控制台dll添加到多个应用程序以进行日志记录。一旦我运行应用程序,它就会很好地记录,但也显示以下错误

 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" />

log4net:错误XmlConfigurator:无法在应用程序的.config文件中找到配置节'log4net'。检查.config文件中的和元素。配置部分应如下所示:

任何想法?

2 个答案:

答案 0 :(得分:2)

添加

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

</configuration>

到你的app / web.config文件

答案 1 :(得分:1)

首先猜测:应用程序,你添加你的dll在其配置文件中没有log4net配置部分。如果是这种情况要么将log4net配置部分添加到应用程序的配置中,要么使用其他方式配置log4net(例如,从一个始终在您的dll旁边的文件中读取配置,但是首选的方法是将所有配置放在一个地方,所以我建议在应用程序的配置中添加一个部分。