log4net .netcore 3.1 method not found

Viewed 2118

Background: This is a .netcore 3.1 web api. It references a DLL that references an SDK to create connections to a third party application. When creating the server object (in the DLL) it throws the following error:

error message

 .net core app
      - DLL containing legacy methods
           - DLL instantiates an SDK server object throwing log4net error

I've added the Microsoft.Extensions.Logging.Log4Net.AspNetCore nuget package and tried the logger factory way:

 public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddLog4Net();

I've also tried this: https://stackify.com/making-log4net-net-core-work/

I have a log4net.config in the solution as well. Any advice on how to resolve the error?

enter image description here

1 Answers

Apache lost the private key that they used to sign log4net assemblies, so older versions of log4net assemblies have a different public key token.

There's not enough information to know if that's what's biting you, but it sounds like it could be related.

If you have a dependency which depends on an old version of log4net with the old public key token, but you resolve a new version of log4net (either because your project references it directly or one of your other dependencies does) then you can get either assembly loading exceptions or missing method exceptions at runtime whenever the code compiled against the old log4net calls one of its methods.

This is because the type names contain the public key token.

The general fix for this is to ensure you only have a single version of log4net in your dependency tree (or at least all versions with the same public key token).

Related