使用Common.Logging与log4net的组件版本兼容问题

引用: 

http://www.cnblogs.com/shijun/p/3713830.html

近期使用了Common.Logging的ILog接口做日志接口,同时利用其log4net适配器与log4net记录器来记录系统日志,在使用过程中碰到了log4net版本问题。

项目组件管理中安装组件包:

PM> Install-Package Common.Logging

PM> Install-Package Common.Logging.Log4Net  【2.0.1版本;依赖Common.Logging (≥ 2.0.0); log4net (= 1.2.10)】

项目中将引用log4net.dll版本为 1.2.10.0,在此配套版本情况下,运行出现错误: {"Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net'"}

也 将log4net组件升级到最新版本1.2.13失败,Install-Package : 将“log4net 1.2.10”更新到“log4net 2.0.3”失败。找不到与“log4net 2.0.3”兼容的“Common.Logging.Log4Net”版本。

 

将Common.Logging.Log4Net版本删除,重新安装以下版本

PM> Install-Package Common.Logging.Log4Net1211  【2.2.0版本;Common.Logging (≥ 2.0.0);Log4Net (≥ 1.2.11)】

项目中log4net.dll版本为 1.2.11.0, 运行OK,升级log4net1.2.13版本,升级成功,运行OK;

注意配置文件中程序集文件名差异

  <common>     <logging>       <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1211">

版本重定向

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">       <dependentAssembly>         <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />         <bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />            </dependentAssembly>          <dependentAssembly>         <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />         <bindingRedirect oldVersion="0.0.0.0-1.2.13.0" newVersion="1.2.13.0" />       </dependentAssembly>     </assemblyBinding>


原因主要是由于log4net version 1.2.11与1.2.10的publicKeyToken不同所致。可利用VS工具SN –T 组件文件名.dll查看公钥。

log4net (≥ 1.2.11)  公钥标记为 669e0ddf0bb1aa2a

log4net (= 1.2.10)  公钥标记为 1b44e1d426115821

 

http://www.nuget.org/packages/Log4Net/

http://www.nuget.org/packages/Common.Logging/

http://www.nuget.org/packages/Common.Logging.Log4Net1211/

http://www.nuget.org/packages/Common.Logging.Log4Net/

http://developer.3l.nl/post/16463925249/log4net-1-2-11-dependency-hell

 

把项目做成了服务,结果怎么使用,都报错, 于是,直接在服务里,有添加"引用"了一边 3个DLL,才算是好使,

很纠结原因是什么...

转载于:https://www.cnblogs.com/davytitan/p/4073629.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值