Log4net版本冲突 [英] Log4net version conflicts

查看:446
本文介绍了Log4net版本冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用log4net 1.2.10登录我的项目。现在我需要引用一个在内部使用log4net 1.2.13进行日志记录的程序集。现在,当我运行项目时,这个新程序集抛出一个异常(无法加载程序集1.2.13;)。



因为log4net 1.2中有很多变化.10到1.2.13,我只是无法将我的日志代码迁移到1.2.13。因此,我需要一些解决方案,我可以保持我的日志代码1.2.10&也可以使用使用log4net 1.2.13的新程序集。



任何帮助将不胜感激。



这就是我已经尝试过的。



a)使用两个文件夹来保存两个不同的版本和放大器;在webconfig的运行时标记中针对版本设置代码库。但没有运气。



我尝试了什么:



二用二不同的文件夹保留两个不同版本的log4net&在webconfig的运行时标记中针对版本设置代码库。但没有运气。

解决方案

您可以更改您的代码以使用最新版本(当然不会很难?它只是记录)。或者,如果程序集兼容,您可以使用程序集重定向让代码加载1.2.13程序集,即使它引用旧版本



重定向汇编版本 [ ^ ]



正如我所说,只有当组件向后兼容时才会有效。



第三种选择是使用两个组件。这是可能的,但很尴尬。您可能需要谷歌获取更多详细信息,但如果您查看VS中引用的属性,您将看到全局的别名字段。在您对旧版本的引用中,将Aliases字段更改为oldlog4net。现在在您的代码中,引用log4net.SomeClass的任何内容都将使用更高版本,并且您将代码更改为引用oldlog4net :: log4net.SomeClass,并将使用您使用oldlog4net别名引用的程序集。

I am currently using log4net 1.2.10 for logging in my project. Now i need to refer to an assembly that uses log4net 1.2.13 internally for logging. Now this new assembly throws an exception ("Unable to load assembly 1.2.13";) while i run the project.

since there are numerous changes in the log4net 1.2.10 to 1.2.13, i just can not migrate my logging code to 1.2.13. Thus i need to have some solution where i could keep my logging code with 1.2.10 & can also use new assembly that uses log4net 1.2.13.

Any help would be appreciated.

This is what i have already tried.

a) used two folder to keep two different version & set the codebase against version in webconfig's runtime tag. But no luck.

What I have tried:

used two diffrent folders to keep two different versions of log4net & set the codebase against version in webconfig's runtime tag. But no luck.

解决方案

You can change your code to use the latest version (surely that won't be hard? it's only logging). Or if the assemblies are compatible you can use assembly redirection to have your code load the 1.2.13 assembly even though it is referencing an older version

Redirecting Assembly Versions[^]

As I said though, that will only work if the assemblies are backward compatible.

The third option is to use both assemblies. This is possible, but awkward. You might need to google for more detailed info but if you look at the properties of the reference in VS you’ll see an "Aliases" field that will be "global". In your reference to the older version change that Aliases field to something like "oldlog4net". Now in your code anything that references "log4net.SomeClass" will use the later version, and you change your code to reference "oldlog4net::log4net.SomeClass" and that will use the assembly you referenced with the "oldlog4net" alias.


这篇关于Log4net版本冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆