【问题标题】:Support for NLog 2.1支持 NLog 2.1
【发布时间】:2014-03-06 11:42:06
【问题描述】:

我想升级到 Nlog 2.1 版。我应该使用哪个版本的 Common Logging 库?

我目前正在使用带有 Nlog 2.0 的 Common Logging 2.0 版。我用 2.1 替换了 NLog v2.0,但它不起作用。有什么帮助吗?

我收到此错误 - 无法从配置部分“common/logging”获取 Common.Logging 的配置。

【问题讨论】:

    标签: c# nlog common.logging


    【解决方案1】:

    您应该使用Common.Logging.NLog20,但您必须添加程序集重定向:

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.2.0" newVersion="2.1.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
    

    您的常用日志配置应如下所示:

    <common>
        <logging>
          <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
            <arg key="configType" value="FILE" />
            <arg key="configFile" value="~/NLog.config" />
          </factoryAdapter>
        </logging>
      </common>
    

    谢天谢地,用于 common.logging 和适配器的 nuget 包已更改 (see here) 您应该可以使用 Common.Logging.NLog21 库。

    【讨论】:

    • 感谢您的回复。我添加了 Common.Logging.NLog20。但是,我应该在 app.config 的哪个部分添加程序集绑定?我的应用程序还应该参考 Common.Logging.dll v 2.1 还是 2.2?
    • 2.1.2,程序集绑定在
    • 嗨,Gary,谢谢,我做了上述更改,但我仍然遇到同样的错误 - 无法从配置部分“common/logging”获取 Common.Logging 的配置:(
    • 内部异常说明了什么?你有没有参考 common.logging.nlog20
    • 创建 common/logging 的配置节处理程序时出错:无法创建类型“Common.Logging.NLog.NLogLoggerFactoryAdapter”
    猜你喜欢
    • 1970-01-01
    • 2018-06-04
    • 2018-08-24
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多