c# - Common.Logging 配置异常

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

当我尝试调用时出现以下异常

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

A first chance exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll

An unhanded exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll

Additional information: Failed obtaining configuration for Common.Logging from configuration section '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"));

我错过了什么?

最佳答案

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

编辑:不是删除,而是将启动元素移到配置部分之后。

关于c# - Common.Logging 配置异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6779711/

相关文章:

c# - 使用 C# 的 C++ 项目

c# - 使用后台 worker 时如何正确处理表单关闭?

c# - 我应该如何比较两个列表中的值?

c# - 32 位和 64 位 C#.NET 中的多目标

c# - 从流加载 XmlDocument 时缺少根元素

c# - 更新 DataTable.Rows[i].ItemArray[j] 值

c# - 如何终止递归函数并返回值

android - RxJava Single and Room 错误处理问题

c# - 使用 .NET 和 Powershell 远程推送 PFX 证书和私钥

c++ - 是否有等待内存可用的 nothrow new ?