我如何解决 log4net 不断更改 publickeytoken

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8743992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:09:45  来源:igfitidea点击:

how do I work around log4net keeping changing publickeytoken

.netdlllog4netpublickeytoken

提问by AndreasKnudsen

We have an asp.net 4.0 project which uses a couple of frameworks which is dependent on log4net version 1.2.10.0. Today I tried to include a new framework which is dependent on log4net version 1.2.11.0, I've been stuck ever since:

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

log4net 1.2.10.0 has publickeytoken = 1b44e1d426115821

log4net 1.2.10.0 有 publickeytoken = 1b44e1d426115821

log4net 1.2.11.0 has publickeytoken = 669e0ddf0bb1aa2a

log4net 1.2.11.0 有 publickeytoken = 669e0ddf0bb1aa2a

Since these are different i cannot use either assembly redirects (to make all frameworks use the same version of log4net) or codebase (to have just the new framework use version 1.2.11.0) through the runtime element in web.config.

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

What are my options here ?

我在这里有什么选择?

(and why the bleep does log4net keep changing publickeytokens between versions, as I understand it a lost key was the reason for the switch between version 1.2.9.0 and 1.2.10.0, did they lose the key yet again? I'll volunteer my dropbox to keep it safe if they need it...)

(以及为什么 bleep 会在版本之间不断更改 publickeytokens,据我所知,丢失的密钥是在 1.2.9.0 和 1.2.10.0 版本之间切换的原因,他们又丢失了密钥吗?我会自愿使用我的保管箱如果他们需要它以确保它的安全......)

Edit: Ok, so the log4net guys apparently had the idea that releasing with two keys was a good idea, but that means that everyframework you make use of needs to agree on whichof the two flavors they prefer, or those frameworks cannot work side by side in the same appdomain. Am I the only one finding this a horrible idea? if everyone did this then everything would break down, right?

编辑:好的,所以 log4net 人员显然认为使用两个键发布是一个好主意,但这意味着您使用的每个框架都需要就他们喜欢的两种风格中的一种达成一致,或者这些框架不能工作并排在同一个应用程序域中。只有我觉得这是一个可怕的想法吗?如果每个人都这样做,那么一切都会崩溃,对吧?

Edit2: As I stated, I'm not using log4net in my business code, but I use several frameworks which depend on 1.2.10.0, and the problem arose when I tried to use a new framework which depended on 1.2.11.0 (new key), so Stefans answer doesn't apply, because the new framework will expect the new key, not the old one

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

回答by David Christiansen

This is how I got things working with version 1.2.11.0.

这就是我使用 1.2.11.0 版的方式。

  1. Curse apache for changing the key in the first place :)
  2. Downloadthe 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
  1. 首先诅咒 apache 更改密钥:)
  2. 下载使用旧密钥签名的 1.2.11.0 版本。
  3. 通过删除对 log4net(新密钥)的任何直接引用并替换为对使用旧密钥签名的程序集的引用来整理您自己的代码。
  4. 通过在您的 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>

回答by jgauffin

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.

我正在使用通过 nuget 下载的最新版本的 log4net。但是,我使用的库之一需要旧版本。我的烦恼使我想到了这个问题。

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.

其他答案的问题在于它们对所有绑定使用相同的 dll 版本。我想将新版本中的功能用于除遗留依赖项之外的所有其他内容。

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

为此,您需要执行以下操作:

  1. Start by downloadingthe 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 actionset to Noneand "Copy if newer" enter image description here
  3. Tell .NET where it can find the old version:
  1. 首先下载旧版本(1.2.11.0 版本)。
  2. 将下载的二进制文件重命名为log4net.1.2.10.dll. 将其包含在您的启动项目中,并将构建操作设置为None“如果更新则复制” 在此处输入图片说明
  3. 告诉 .NET 在哪里可以找到旧版本:

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 hrefattributes identifies where the old version is. Hence all other requests for log4net will point on the new version.

href属性标识了旧版本。因此,对 log4net 的所有其他请求都将指向新版本。

回答by Stefan Egli

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:

您可以下载使用旧密钥签名的 log4net 1.2.11.0 版本。他们的常见问题解答中解释了更改为新密钥的原因:

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

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)

(基本上新密钥是公开可用的,出于某种原因,他们不想在分发中包含旧密钥。我不清楚为什么他们不只是公开旧密钥)

回答by alex

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.

不知道它是否适合您的特定情况,但您可以重新编译其中一个框架,因此它们将使用具有相同公钥的 log4net。就我而言,它是 FluentNHibernate,它使用 log4net 1.2.10 和 Combres with log4net 1.2.11 和新密钥。我下载了用旧密钥签名的 log4net 1.2.11 并用它重新编译了 Combress。之后添加程序集绑定重定向从 1.2.10 到 1.2.11 并开始工作。

回答by George Huang

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:

我试图转到上面提供的链接,但似乎 Apache 站点中的所有链接都不起作用。然后这就是我为解决问题所做的工作:

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.

在 Visual Studio 中,使用 Nuget 下载并安装最新版本的 log4net (1.2.13.0)。NuGet 包管理器会自动下载并升级所有 log4net(1.2.11.0) 到最新版本。

回答by Mark J Miller

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.

这不一定在所有情况下都有效,但是因为使用 log4net 的项目是 OSS,所以我下载了源代码,用我正在使用的版本替换了冲突的 log4net 版本并重新构建了项目。在我的情况下,它是 Topshelf,所以我现在有一个 Topshelf 程序集版本,它是用我正在使用的相同版本的 log4net 构建的,现在我可以毫无问题地引用两者。