NLog 1.5 Common.Logging.NLog10 unable to instaciante NLogger



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

App.config 下的通用日志记录配置

<?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 和配置文件参数。

我的 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

通用。日志记录版本 2.1.1

NLog 版本 1.5

C# 框架 3.5

控制台项目

似乎使用 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。

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

相关内容

最新更新