serilog / serilog-extensions-logging

Serilog provider for Microsoft.Extensions.Logging
Apache License 2.0
309 stars 99 forks source link

Forced to Use Microsoft.Extensions.Logging 2.0.0 Even if Using ASP.Net Core 1.1 on net461 #115

Closed adamrodger closed 5 years ago

adamrodger commented 6 years ago

The dependencies for Net 4.6.1 upgrade the minimum version of Microsoft.Extensions.Logging to 2.0.0 even though .Net 4.6 only requires 1.0.0.

This means if you install the package into a solution using .Net 4.6.1 and ASP.Net Core 1.1 then you receive an exception at runtime:

System.TypeLoadException : Method 'get_Name' in type 'Microsoft.Extensions.Options.ConfigurationChangeTokenSource`1' from assembly 'Microsoft.Extensions.Options.ConfigurationExtensions, Version=1.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
Stack Trace:
   at Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure[TOptions](IServiceCollection services, IConfiguration config)

I really don't think it makes sense to require different major versions of the same dependency depending on the target framework, especially in a way that can cause runtime exceptions in consuming projects.

The line causing this problem is:

https://github.com/serilog/serilog-extensions-logging/blob/0faeefb1f27ef6ed3ccb760feebe013856c289cc/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj#L32

nblumhardt commented 6 years ago

Thank you @adamrodger - I agree, we should probably switch wholeheartedly to the 2.0 packages in a new release.

Help appreciated if anyone is interested in sending a PR.

raviganesan commented 6 years ago

If anyone got this error, ensure you install same version of the following from nuget in my case, I had 1.1.2, made all assemblies to same version to fix the issue.

  1. Microsoft.Extensions.Logging
  2. Microsoft.Extensions.Configuration
  3. Microsoft.Extensions.Options.ConfigurationExtensions

Note: If you referenced a project and if that had Microsoft.Extensions.Logging 2.0.0, you need to go to that project and match the version. (in my case, I downgraded to 1.1.2)

simenhagelid commented 5 years ago

Had the same problem with conflicts and downgrade was not possible. I tried a small change, <PackageReference Include="Microsoft.Extensions.Logging" Version="2.*" />, it seems to work.

nblumhardt commented 5 years ago

dev is now targeting 2.0.0.