developer tip

log4net에서 publickeytoken을 계속 변경하려면 어떻게해야하나요?

optionbox 2020. 8. 24. 08:10
반응형

log4net에서 publickeytoken을 계속 변경하려면 어떻게해야하나요?


log4net 버전 1.2.10.0에 의존하는 몇 가지 프레임 워크를 사용하는 asp.net 4.0 프로젝트가 있습니다. 오늘 저는 log4net 버전 1.2.11.0에 의존하는 새로운 프레임 워크를 포함하려고 노력했습니다.

log4net 1.2.10.0에는 publickeytoken = 1b44e1d426115821이 있습니다.

log4net 1.2.11.0에는 publickeytoken = 669e0ddf0bb1aa2a가 있습니다.

이들은 다르기 때문에 web.config의 런타임 요소를 통해 어셈블리 리디렉션 (모든 프레임 워크가 동일한 버전의 log4net을 사용하도록 함) 또는 코드베이스 (새 프레임 워크 만 버전 1.2.11.0을 사용하도록 함)를 사용할 수 없습니다.

여기서 내 옵션은 무엇입니까?

(그리고 왜 log4net이 버전간에 공개 키 토큰을 계속 변경하는 삐 소리가 나는지 이해합니다. 키를 잃어버린 것이 버전 1.2.9.0과 1.2.10.0 사이의 전환의 이유 였음을 이해합니다. 그들은 키를 다시 잃어 버렸나요? 필요한 경우 안전하게 보관하기 위해 ...)

편집 : 좋아, 그래서 log4net 사람들은 두 개의 키로 릴리스하는 것이 좋은 생각이라는 생각을 분명히 가지고 있었지만 사용 하는 모든 프레임 워크가 선호하는 두 가지 맛 중 어느 것이 선호 되는지 동의해야 함을 의미 합니다. 동일한 appdomain에서 나란히. 이 끔찍한 아이디어를 찾는 유일한 사람입니까? 모두가 이렇게하면 모든 것이 무너질 것입니다.

Edit2 : 언급했듯이 비즈니스 코드에서 log4net을 사용하지 않지만 1.2.10.0에 의존하는 여러 프레임 워크를 사용하고 있으며 1.2.11.0 (새 키)에 의존하는 새 프레임 워크를 사용하려고 할 때 문제가 발생했습니다. ), 따라서 Stefans 대답은 적용되지 않습니다. 새로운 프레임 워크는 이전 키가 아닌 새 키를 예상하기 때문입니다.


이것이 내가 버전 1.2.11.0으로 작업하는 방법입니다.

  1. 애초에 키를 변경하는 저주 아파치 :)
  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>

Nuget을 통해 다운로드 한 최신 버전의 log4net을 사용하고 있습니다. 그러나 사용중인 라이브러리 중 하나에는 이전 버전이 필요합니다. 내 문제는 나를이 질문으로 이끌었다.

다른 답변의 문제는 모든 바인딩에 대해 동일한 dll 버전을 사용하고 있다는 것입니다. 레거시 종속성을 제외한 다른 모든 기능에 새 버전의 기능을 사용하고 싶습니다.

이를 수행하려면 다음을 수행해야합니다.

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


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)


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.


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.


위에 제공된 링크로 이동하려고했지만 Apache 사이트의 모든 링크가 작동하지 않는 것 같습니다. 그런 다음 문제를 해결하기 위해 다음을 수행했습니다.

Visual Studio에서 Nuget을 사용하여 최신 버전의 log4net (1.2.13.0)을 다운로드하고 설치합니다. NuGet 패키지 관리자는 모든 log4net (1.2.11.0)을 자동으로 다운로드하고 최신 버전으로 업그레이드합니다.

참고 URL : https://stackoverflow.com/questions/8743992/how-do-i-work-around-log4net-keeping-changing-publickeytoken

반응형