serilog-aspnetcore
serilog-aspnetcore copied to clipboard
Structured logging does not work with Microsoft.Extensions.Logging.Abstractions 6.0.0
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
- The console should display the log with the usual colour coding.
- Note: it does display the log, but without the colour coding.
- 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
- net5.0
- Serilog.AspNetCore 5.0.0
- Serilog.Sinks.ApplicationInsights 3.1.0
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).
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.