log4net:ERROR XmlConfigurator:在应用程序的.config文件中未找到配置部分'log4net'。

3

我已经创建了一个独立的控制台应用程序来记录日志,然后将这个单一的控制台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:ERROR XmlConfigurator:在应用程序的.config文件中找不到配置部分'log4net'。检查您的.config文件中的和元素。配置部分应该如下所示:

有什么想法吗?

2个回答

2

添加

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

</configuration>

添加到你的应用程序/web.config文件中


我使用了第三个log.config文件,并将所有配置添加到该文件中,然后加载该配置文件。 - Pankaj Saha
你是如何加载配置文件的?你确定在第一次记录日志之前该配置已经生效了吗? - Arsen Mkrtchyan

1

初步猜测:您添加的 DLL 文件没有在应用程序的配置文件中设置 log4net 配置部分。如果是这种情况,您需要将 log4net 配置部分添加到应用程序的配置文件中,或者使用其他方式对 log4net 进行配置(例如从始终位于 DLL 旁边的文件中读取配置,但最好的方式是将所有配置放在一个地方,因此我建议将该部分添加到应用程序的配置中)。


是的,那个dll有不同的配置文件用于日志配置。 - Pankaj Saha

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接