Hi,
I'm trying to wire up "legacy" custom implementations of Microsoft.Extensions.Logging.ILoggerProvider and Microsoft.Extensions.Logging.ILogger as a Serilog sink.
My Serilog configuration looks like this:
var customProviders = new LoggerProviderCollection();
customProviders.AddProvider(new CustomLoggerProvider());
// Configure Serilog
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.WithThreadId()
.Enrich.FromLogContext()
// Hook up custom providers as Serilog sink
.WriteTo.Providers(customProviders)
// More log sinks here
// [...]
.CreateLogger();
IHostBuilder builder = Host.CreateDefaultBuilder(args)
// Configure a stack of other app services
// [...]
// Replace default logging providers from Host.CreateDefaultBuilder() with Serilog
.ConfigureLogging(logBuilder =>
{
logBuilder.SetMinimumLevel(LogLevel.Trace);
logBuilder.ClearProviders();
})
.UseSerilog(providers: customProviders)
IHost host = builder.Build();
At runtime, my custom logger provider gets called and returns my custom ILogger implementations. So far so good.
This particular logging provider needs some context provided via ILogger.BeginScope() to complete its logging.
But, when I set breakpoints in my custom logger's implementations of ILogger.Log(...) and ILogger.BeginScope(...) methods, the breakpoint inside Log(...) gets hit, but the BeginScope<TState>(...) breakpoint never gets hit. The code being logged definitely calls _logger.BeginScope<TState>(foo) with the state information that the custom logger needs. It looks like Serilog isn't passing the BeginScope<TState>() information on to the CustomLogger instances, so they never get a chance to capture the information they need to complete the logging.
Am I using the APIs incorrectly or is this a bug?
Hi,
I'm trying to wire up "legacy" custom implementations of
Microsoft.Extensions.Logging.ILoggerProviderandMicrosoft.Extensions.Logging.ILoggeras a Serilog sink.My Serilog configuration looks like this:
At runtime, my custom logger provider gets called and returns my custom
ILoggerimplementations. So far so good.This particular logging provider needs some context provided via
ILogger.BeginScope()to complete its logging.But, when I set breakpoints in my custom logger's implementations of
ILogger.Log(...)andILogger.BeginScope(...)methods, the breakpoint insideLog(...)gets hit, but theBeginScope<TState>(...)breakpoint never gets hit. The code being logged definitely calls_logger.BeginScope<TState>(foo)with the state information that the custom logger needs. It looks like Serilog isn't passing theBeginScope<TState>()information on to theCustomLoggerinstances, so they never get a chance to capture the information they need to complete the logging.Am I using the APIs incorrectly or is this a bug?