Skip to content

Conversation

nblumhardt
Copy link
Member

Serilog 4.2 stabilized the use of dotted.identifiers in message templates. Properties captured using this mechanism have dotted names, so when {a.b} is captured in a log statement, the resulting property is called "a.b", it doesn't become an object a with sub-object b.

The Nest() function in this PR implements the conversion from dotted names to nested objects so that dotted identifiers can effectively capture fully-structured data, for back-ends/output formats that support it.

Given the event:

Log.Information("HTTP {request.method} {request.path}: {response.status_code}", "GET", "/example", 200);

And the Serilog.Expressions template:

    .WriteTo.Console(new ExpressionTemplate("{ {@t, @m, @l, @x, ..Nest(@p)} }\n"))

The resulting JSON output will be:

{"@t":"2025-02-27T12:28:17.3004399+10:00","@m":"HTTP GET /example: 200","@l":"Information",
"request":{"method":"GET","path":"/example"},"response":{"status_code":200}}

A separate commit is included which updates the project to match the newer Actions-based builds.

@nblumhardt
Copy link
Member Author

Build failure is expected because of the switch to Actions.

@nblumhardt nblumhardt merged commit 1b6a42d into serilog:dev Feb 28, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant