launchdarkly / dotnet-logging

Logging abstraction used by LaunchDarkly .NET-based libraries
Other
1 stars 2 forks source link

add .NET Core logging adapter #2

Closed eli-darkly closed 3 years ago

eli-darkly commented 3 years ago

The standard logging abstraction for .NET Core / ASP.NET Core applications is Microsoft.Extensions.Logging. Much like Common.Logging, this is a facade that delegates to whatever logging provider has been configured by the application.

This PR adds an adapter that directs all LaunchDarkly.Logging output to Microsoft.Extensions.Logging. To create this, you call Logs.CoreLogging(loggingFactory)— where loggingFactory is an implementation of Microsoft.Extensions.Logging.ILoggerFactory. A .NET Core application would typically either obtain the ILoggingFactory through dependency injection, or create it programmatically. I don't think there is such a thing as a global ILoggingFactory that we could automagically access, so we do need for them to pass that parameter to us.

Microsoft.Extensions.Logging is not part of the .NET Standard API— it's a package that's distributed with .NET Core. So we don't want to have any dependencies on it from the .NET Standard 2.0 build of LaunchDarkly.Logging; that would cause problems for instance in the Xamarin SDK, which uses .NET Standard dependencies and does not have access to .NET Core. So, I've added a specific .NET Core 2.0 target to this package; the new method is included only in that target, through conditional compilation. Any .NET Core / ASP.NET Core application that references LaunchDarkly.Logging will get the .NET Core 2.0 version, whereas any portable code that is written against .NET Standard will get the .NET Standard 2.0 version that doesn't have this new adapter.

eli-darkly commented 3 years ago

Correction: our lowest compatible .NET Core version is 2.1, not 2.0. .NET Core 2.0 is EOL and won't be supported in any of our upcoming major version releases.