Can NLog v2 be used with Common.Logging

狂风中的少年 提交于 2019-12-14 03:40:50

问题


I tried using these together today, and was getting a version mismatch, as it's looking for NLog v1.

Does Common.Logging support NLog v2 yet?

If not, does anyone know if an assembly version redirect can safely be used?


回答1:


You can simply do assembly redirect in app.config or web.config, and CommonLogging will just work fine with NLog2 by using NLog2 as logging framework:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

The only issue is if you want to redirect NLog message to some other logging framework using CommonLogging 2.0, then there is a compatibility issue. But that is a very unusual use case.




回答2:


If you used Nuget to get the Common.Logging.NLog library, the package will download Common.Logging v2.0 dependency. If you use Nuget to update Common.Logging, it will update it to v2.1.1.0, which will prevent the Could not load file or assembly 'NLog, Version=1.0.0.505 error.



来源:https://stackoverflow.com/questions/6027997/can-nlog-v2-be-used-with-common-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!