我如何处理 log4net 保持更改 public 令牌

我们有一个 asp.net 4.0项目,它使用了一些依赖于 log4net 1.2.10.0版本的框架。今天我试图包含一个新的框架,这个框架依赖于 log4net 1.2.11.0版本,从那以后我就一直被卡住了:

Log4net 1.2.10.0具有 pubickeytoken = 1b44e1d426115821

Log4net 1.2.11.0有 pubickeytoken = 669e0ddf0bb1aa2a

由于这些不同,我不能通过 web.config 中的运行时元素使用汇编重定向(使所有框架使用相同版本的 log4net)或代码库(使新框架使用1.2.11.0版本)。

我还有什么选择?

(还有为什么 log4net 在不同版本之间不断地更改 public 密钥,据我所知,一个丢失的密钥是在1.2.9.0和1.2.10.0之间切换的原因,他们又丢失密钥了吗?如果他们需要的话,我会主动提供我的投递箱来保证它的安全... ...)

编辑: 好吧,log4net 的人显然认为用两个键发布是一个好主意,但这意味着 每个框架需要使用他们喜欢的两种风格的 哪个,或者这些框架不能在同一个应用程序域并行工作。只有我觉得这主意糟透了吗?如果每个人都这样做,那么一切都会崩溃,对不对?

Edit2: 正如我所说的,我没有在我的业务代码中使用 log4net,但是我使用了几个依赖于1.2.10.0的框架,当我试图使用一个依赖于1.2.11.0的新框架(新键)时,问题出现了,所以 Stefans 的回答不适用,因为新框架需要的是新键,而不是旧键

37552 次浏览

You can download a version of log4net 1.2.11.0 that is signed with the old key. The reason why the changed to a new key is explained in their FAQ:

http://logging.apache.org/log4net/release/faq.html#two-snks

(Basically the new key is publicly available and for some reason they did not want to include the old key in the distribution. It is not clear to me why they did not just make the old key publicly available though)

This is how I got things working with version 1.2.11.0.

  1. Curse apache for changing the key in the first place :)
  2. Download the version of 1.2.11.0 signed with the old key.
  3. Sort out your own code out by removing any direct references to log4net (new key) and replace with a reference to the assembly signed with the old key.
  4. Sort out any dependant assemblies you may have by including this segment in your web/app.config
   <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.10.0"
newVersion="1.2.11.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

This won't necessarily work in all cases, but because the project that was using log4net was OSS I downloaded the source, replaced the conflicting version of log4net with the version I was using and rebuilt the project. In my case it was Topshelf, so I now have a version of the Topshelf assembly that was built with the same version of log4net I'm using and now I can reference both without a problem.

Don't know is it suitable for your particular case or not, but you can recompile one of the frameworks, so they will use log4net with the same public key. In my case it was FluentNHibernate which uses log4net 1.2.10 and Combres with log4net 1.2.11 with new key. I downloaded log4net 1.2.11 signed with old key and recompiled Combress with it. After that added assembly binding redirect from 1.2.10 to 1.2.11 and it starts working.

I am using the latest version of log4net which I downloaded through nuget. However, one of the libraries that I'm using requires the old version. My troubles led me to this question.

The problem with the other answers are that they are using the same dll version for all bindings. I want to use features in the new version for everything else but the legacy dependency.

To be able to do that you need to do the following:

  1. Start by downloading the old version (version of 1.2.11.0).
  2. Rename the downloaded binary to log4net.1.2.10.dll. Include it in your startup project with Build action set to None and "Copy if newer" enter image description here
  3. Tell .NET where it can find the old version:

App.config

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" />
<codeBase version="1.2.10.0" href="log4net.1.2.10.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>

The href attributes identifies where the old version is. Hence all other requests for log4net will point on the new version.

I tried to go to the links provided above, but it seems like all the links in the Apache site are not working. Then this is what I did to resolve the issue:

From your Visual Studio, use Nuget to download and install the latest version of log4net (1.2.13.0). The NuGet package manager will automatically download and upgrade all the log4net(1.2.11.0) to the latest version.