IdentityModel.OidcClient icon indicating copy to clipboard operation
IdentityModel.OidcClient copied to clipboard

Use Microsoft.Extensions.Logging.Abstractions to reduce dependencies

Open SergeySvirsky opened this issue 1 year ago • 7 comments

Currently OidcClient proj referrences Microsoft.Extensions.Logging package. It's being used in OidcClientOptions in next way:

   public ILoggerFactory LoggerFactory { get; set; } = new LoggerFactory();

And in client projects can see next lines:

options.LoggerFactory.AddSerilog(serilog);

Shouldn't we change that into next way:

  1. Referrence Microsoft.Extensions.Logging.Abstractions in OidcClient proj
  2. Use NullLoggerFactory in OidcClientOptions
  3. Use Microsoft.Extensions.Logging in client projects:
options.LoggerFactory = new LoggerFactory().AddSerilog(serilog);

SergeySvirsky avatar Oct 27 '23 12:10 SergeySvirsky

See https://github.com/IdentityModel/IdentityModel.OidcClient/pull/397

SergeySvirsky avatar Oct 27 '23 13:10 SergeySvirsky

Hi,

thanks! What's the benefit of that?

leastprivilege avatar Oct 29 '23 06:10 leastprivilege

Well..

In that case IdentityModel.OidcClient package will not add dependencies which it doesn't use or doesn't need: i.e. referrences package A which referrences package B and only code from B is really required.

JFI:

Microsoft.Extensions.Logging in case of netstandard 2.0 has next dependencies:

[Microsoft.Bcl.AsyncInterfaces](https://www.nuget.org/packages/Microsoft.Bcl.AsyncInterfaces/) (>= 7.0.0)
[Microsoft.Extensions.DependencyInjection](https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection/) (>= 7.0.0)
[Microsoft.Extensions.DependencyInjection.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection.Abstractions/) (>= 7.0.0)
[Microsoft.Extensions.Logging.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Abstractions/) (>= 7.0.0)
[Microsoft.Extensions.Options](https://www.nuget.org/packages/Microsoft.Extensions.Options/) (>= 7.0.0)
[System.Diagnostics.DiagnosticSource](https://www.nuget.org/packages/System.Diagnostics.DiagnosticSource/) (>= 7.0.0)

And Microsoft.Extensions.Logging.Abstractions has only next dependencies for netstandard2.0:

[System.Buffers](https://www.nuget.org/packages/System.Buffers/) (>= 4.5.1)
[System.Memory](https://www.nuget.org/packages/System.Memory/) (>= 4.5.5)

PS: on my project due to such depencies from IdentityModel.OidcClient and another package got a runtime issue that one of dependencies wasn't found (yeah, compiler lost it during build) so I had to explicitly reference Microsoft.Extensions.Logging project to make it working again.

SergeySvirsky avatar Oct 30 '23 08:10 SergeySvirsky

OK.

What will happen to existing clients when they call e.g.

options.LoggerFactory.AddSerilog(serilog);

Will it throw - or just do no logging?

leastprivilege avatar Oct 30 '23 08:10 leastprivilege

yeah, thats a good spot.. it will do no logging as NullLoggerFactory is being used

So from that point of view that change is breaking and probably its better to keep it as it is

SergeySvirsky avatar Oct 30 '23 13:10 SergeySvirsky

But it will not break (e.g. throw an exception) ?

I personally agree with reducing dependencies. We will do a major release anyway soon....

leastprivilege avatar Oct 31 '23 08:10 leastprivilege

Will not break link

  • AddSerilog calls AddProvider which do nothing
  • CreateLogger returns NullLogger.Instance

SergeySvirsky avatar Oct 31 '23 12:10 SergeySvirsky