无法从配置部分"common/logging"获取Common.Logging的配置 [英] Failed obtaining configuration for Common.Logging from configuration section 'common/logging'

查看:539
本文介绍了无法从配置部分"common/logging"获取Common.Logging的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下日志记录程序集配置控制台应用程序:

I'm trying to configure a console application with the following logging assemblies:

  • Common.Logging.dll(2.1.0.0)
  • Common.Logging.Log4Net1211.dll(2.1.0.0)
  • log4net.dll(1.2.11.0)

如果以编程方式配置了记录器,则一切正常:

If the logger gets configured programmatically then everything works fine:

NameValueCollection properties = new NameValueCollection(); properties["showDateTime"] = "true";    
Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties);

但是,如果我尝试使用以下配置文件启动它,则会炸毁:

But if I try to launch it using the following configuration file, it blows up:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="common">
            <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
        </sectionGroup>
    </configSections>

    <common>
    <logging>
        <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
             <arg key="configType" value="FILE-WATCH"/>
            <arg key="configFile" value="~/Log4NET.xml"/>
        </factoryAdapter>
    </logging>
</common>
</configuration>

这些是相关的错误消息:

These are the relevant error messages:

{"Unable to cast object of type 'System.Configuration.DefaultSection' to type 'System.Configuration.AppSettingsSection'."}

{"Failed obtaining configuration for Common.Logging from configuration section 'common/logging'."}

似乎无法解析我的配置文件,有人知道正确的格式应该是其他格式吗?我使用官方文档创建了配置文件. >

It seems to being unable to parse my configuration file, does anyone know what the correct format should be or is it something else that's wrong? I created my configuration file using the official documentation.

推荐答案

您的应用程序有两个问题(我下载了一个):

There are two problems with your application (the one I downloaded):

  1. 您在app.config中的configSections看起来像这样:

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

    <sectionGroup name="common">
        <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>

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

注意log4net-section被声明两次了吗?删除第一个.

Notice that the log4net-section is declared twice? Remove the first one.

  1. 删除第一个log4net部分后,我得到以下信息:

无法加载文件或程序集'log4net,版本= 1.2.11.0,区域性=中性,PublicKeyToken = 669e0ddf0bb1aa2a'或其依赖项之一.找到的程序集的清单定义与程序集引用不匹配. (来自HRESULT的异常:0x80131040)

Could not load file or assembly 'log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我从log4net网站上下载了log4net 1.2.11.0,将其解压缩,解除阻止该dll并替换了示例中的log4net,这似乎可以正常工作.

I downloaded log4net 1.2.11.0 from the log4net website, unzipped it, unblocked the dll and replaced the log4net in your example and it seems to work.

这篇关于无法从配置部分"common/logging"获取Common.Logging的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆