2012-04-04 100 views
3

我已经为日志创建了一个单独的控制台应用程序,然后将该单个控制台dll添加到多个应用程序进行日志记录。当我运行应用程序,它是记录良好,但也呈现出以下错误log4net:错误XmlConfigurator:无法在应用程序的配置文件中找到配置节'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" /> 

log4net的:ERROR XmlConfigurator:无法找到应用程序的.config文件配置部件“log4net的”。检查你的.config文件中的和元素。配置部分应如下所示:

有什么想法?

回答

1

第一次猜测:应用程序,您添加您的DLL没有其配置文件中的log4net配置节。如果是这种情况,可以将log4net config部分添加到应用程序的配置中,或者使用其他方式来配置log4net(例如,从始终位于dll旁边的文件读取配置文件,但首选的方法是将所有配置都放在一个位置,所以我建议在应用程序的配置中添加一段)。

+0

是,该DLL为日志配置不同的配置文件。 – 2012-04-04 12:00:12

2

添加

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

</configuration> 

到您的应用程序/ web.config文件

+0

我已经使用了第三个log.config文件并将所有配置添加到该文件并加载该配置文件。 – 2012-04-04 11:58:30

+0

比显示你加载配置文件吗?你确定配置在你的第一次日志之前工作吗? – 2012-04-04 12:03:41