Closed christianerbsmehl closed 2 years ago
@christianerbsmehl I took a look at this. In 3.2 we added the feature to add support for IDynamicMessageProcessor which adds things like span and traceID to add context to logs. Unfortunately, I think this broke compatibility with the structured logging. I am looking for a work around.
@christianerbsmehl the short answer to this is that the IDynamicMessageProcessor adds context to logs by calling the formatter ahead of time and then appends data. Whereas the serilog implementation uses the values in TState of Log
The IDynamicMessageProcessor is a Steeltoe thing, isn't it? Can you give me some context why this was introduced and what's the use case? From the linked issue (https://github.com/SteeltoeOSS/Steeltoe/issues/835) I understood that TraceId and SpanId should be included in the console output. With .NET Core 3.1 and using Serilog, SpandId and TraceId were automatically included in the properties of every log message, but with .NET 6 (also .NET 5) they are missing by default (https://github.com/serilog/serilog-aspnetcore/issues/207). So maybe the problem you were trying to solve with the IDynamicMessageProcessor should have been solved elsewhere (e.g. only for the console logger provider) or can be solved using a serilog enricher?
Describe the bug
After upgrading
Steeltoe.Extensions.Logging.DynamicSerilogBase
from version3.1.3
to3.2.0
, structured logging with Serilog is broken, which means that message properties are not extracted from the log message. Additionally, the console output is not colored anymore. I created a sample project to demonstrate the issue: https://github.com/christianerbsmehl/steeltoe-serilogTo narrow down the problem, I configured the Serilog file sink with the compact JSON formatter. I found out, that with DynamicSerilogBase 3.2.0 the message template is missing the curly braces around the message properties:
Using DynamicSerilogBase 3.1.3, output looks like this:
Note the curly braces around
value
in the message template and the extracted"value":"value"
property.Steps to reproduce
Steps to reproduce the behavior:
Steeltoe.Extensions.Logging.DynamicSerilogBase 3.2.0
andSerilog.AspNetCore 6.0.1
In
Program.cs
:In
appSettings.json
:For details please refer to the sample project I provided above.
Expected behavior
Message properties should be extracted again and the message template should have curly braces around properties.
Environment