serilog / serilog-aspnetcore

Serilog integration for ASP.NET Core
Apache License 2.0
1.32k stars 209 forks source link

Structured logging does not work with Microsoft.Extensions.Logging.Abstractions 6.0.0 #291

Closed jb-medivet closed 4 months ago

jb-medivet commented 2 years ago

Description When writing logs using the ILogger<T> API from M.E.L.A v6.0.0, Serilog does not detect any log parameters. Works as expected after downgrading to v5.0.0

Reproduction

Serilog configured with:

        public static IHostBuilder ConfigureLogger(this IHostBuilder builder)
            => builder.UseSerilog((context, services, loggerConfiguration)
                => loggerConfiguration
                    .ReadFrom.Configuration(context.Configuration)
                    .WriteTo.Console()
                    .WriteTo.ApplicationInsights(services.GetRequiredService<TelemetryConfiguration>(), TelemetryConverter.Traces));

Logs written as:

using Microsoft.Extensions.Logging;
...
private readonly ILogger<MyClass> _logger;
...
_logger.LogInformation("The value is {Value}", value);

Expected behaviour

  1. The console should display the log with the usual colour coding.

    • Note: it does display the log, but without the colour coding.
  2. App Insights should contain the log with custom dimensions 'Value' = "[the-value]" and 'MessageTemplate' = "The value is {Value}"

    • Note: it does contain the log, but the 'Value' custom dimension is not included, and the 'MessageTemplate' contains the resolved string i.e. "The value is [the-value]"

Relevant package, tooling and runtime versions

nblumhardt commented 2 years ago

Thanks for taking the time to let us know. Would it be possible to assemble a reproduction, ideally using only the Console sink and CompactJsonFormatter() or JsonFormatter(), that demonstrates the issue? (If not, this may be a Serilog.Sinks.ApplicationInsights problem, and would need to be transferred to/dealt with in that repository).

christianerbsmehl commented 2 years ago

Same here. I just upgraded a .NET Core 3.1 project to .NET 6 using Serilog.AspNetCore 6.0.1 and Serilog.Sinks.Splunk 3.7.0. Same observations: Console output is not colored anymore and message properties in Splunk are missing. I'll try to provide you a sample project.

Edit: While creating the sample project I realized that this problem only occurs if I add the Steeltoe.Extensions.Logging.DynamicSerilogBase NuGet package. I will file an issue in their repository.