【问题标题】:Common.Logging config exceptionCommon.Logging 配置异常
【发布时间】:2011-10-10 10:02:14
【问题描述】:

当我尝试调用时遇到以下异常

var log = LogManager.GetLogger(this.GetType());

Common.Logging.dll 中出现“Common.Logging.ConfigurationException”类型的第一次机会异常

Common.Logging.dll 中出现“Common.Logging.ConfigurationException”类型的未经处理的异常

附加信息:无法从配置部分“common/logging”获取 Common.Logging 的配置。

这是一个引用

的 .NET 4 应用程序
  • log4net.dll
  • Common.Logging.dll
  • Common.Logging.log4net.dll

我的 app.config 有以下内容:

<?xml version="1.0"?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
    <configSections>
        <sectionGroup name="common">
            <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
        </sectionGroup>
    </configSections>
    <common>
        <logging>
            <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
                <arg key="level" value="ALL" />
                <arg key="showLogName" value="true" />
                <arg key="showDataTime" value="true" />
                <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
            </factoryAdapter>
        </logging>
    </common>
</configuration>    

我想这样打电话:

var log = LogManager.GetLogger(this.GetType());
log.Debug(m => m("testing"));

我错过了什么?

【问题讨论】:

    标签: c# .net exception-handling app-config common.logging


    【解决方案1】:

    如果您从配置中删除元素 startup,它运行正常。

    编辑:不要删除,只需将启动元素移动到 configsections 之后。

    【讨论】:

    • 哇!确实,删除它并且它有效。如果您说明“为什么”,则加分。
    • 我相信这是因为配置架构的验证或加载方式。
    • 不错的一个!此答案对 VS2012/.Net 4.5、Common.Logging 2.1.1、Common.Logging.Log4Net 2.0.0 和 log4net 1.2.10 仍然有效
    • 来自docs on the configSections element:“如果这个元素在配置文件中,它必须是元素的第一个子元素。”
    • 如果问题仍然存在? :(还有其他想法吗?
    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-29
    • 2010-12-28
    相关资源
    最近更新 更多