IdentityModel.OidcClient
IdentityModel.OidcClient copied to clipboard
Use Microsoft.Extensions.Logging.Abstractions to reduce dependencies
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:
- Referrence Microsoft.Extensions.Logging.Abstractions in OidcClient proj
- Use NullLoggerFactory in OidcClientOptions
- Use Microsoft.Extensions.Logging in client projects:
options.LoggerFactory = new LoggerFactory().AddSerilog(serilog);
See https://github.com/IdentityModel/IdentityModel.OidcClient/pull/397
Hi,
thanks! What's the benefit of that?
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.
OK.
What will happen to existing clients when they call e.g.
options.LoggerFactory.AddSerilog(serilog);
Will it throw - or just do no logging?
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
But it will not break (e.g. throw an exception) ?
I personally agree with reducing dependencies. We will do a major release anyway soon....
Will not break link
-
AddSerilog
callsAddProvider
which do nothing -
CreateLogger
returnsNullLogger.Instance