【问题标题】:NLog 1.5 Common.Logging.NLog10 unable to instaciante NLoggerFactoryAdapterNLog 1.5 Common.Logging.NLog10 无法安装 NLoggerFactoryAdapter
【发布时间】:2014-04-01 21:01:57
【问题描述】:

我第一次尝试将 NLog 与 common.logging 一起使用。我在一个测试项目中实现了 NLog,一切正常,然后尝试应用 common.logging,但我遇到了一些困难。

App.config下的Common.logging配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="common">
            <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
        </sectionGroup>
    </configSections>
    <common>
        <logging>
            <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog10">
                <arg key="configType" value="FILE" />
                <arg key="configFile" value="~/NLog.config" />
            </factoryAdapter>
        </logging>
    </common>
</configuration>

我遇到的错误在 Common.Logging.LogManager 第 317 行

private static ILoggerFactoryAdapter BuildLoggerFactoryAdapterFromLogSettings(LogSetting setting)
        {
...
adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType, args);
...
}

在调试时,我可以看到 configType 和 configFile args 都在传递。

我的 NLog.config 设置为始终复制到我的 vs.

我得到的错误是:

An unhandled exception of type 'Common.Logging.ConfigurationException' occurred in NLogTutorial1.exe

Additional information: Unable to create instance of type Common.Logging.NLog.NLogLoggerFactoryAdapter. Possible explanation is lack of zero arg and single arg NameValueCollection constructors

Visual Studio 2008

Common.Logging 版本 2.1.1

NLog 1.5 版

C# 框架 3.5

控制台项目

【问题讨论】:

    标签: c# visual-studio-2008 .net-3.5 nlog common.logging


    【解决方案1】:

    按照以下步骤绝对可以解决所有配置和缺少 dll 的问题。 https://stackoverflow.com/a/27825054/384554

    【讨论】:

      【解决方案2】:

      似乎使用 Common.Logging.NLog20 解决了这个问题。 来自本站http://netcommon.sourceforge.net/docs/2.1.0/reference/html/ch01.html

      Common.Logging.NLog20 -> 链接到 NLog 2.0.0.2

      Common.Logging.NLog10 -> 链接到 NLog 1.0.0.505

      所以对于 NLog 1.5,应该使用 NLog20。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-09
        • 1970-01-01
        • 2020-10-01
        • 1970-01-01
        • 2016-10-15
        • 1970-01-01
        • 1970-01-01
        • 2021-07-26
        相关资源
        最近更新 更多