In Serilog, how can I remove empty brackets from JSON formatted log messages when using {Properties} format specifier? In Serilog, how can I remove empty brackets from JSON formatted log messages when using {Properties} format specifier? json json

In Serilog, how can I remove empty brackets from JSON formatted log messages when using {Properties} format specifier?


You could use this serilog extension:

dotnet add package Serilog.Expressions

See github serilog-expressions: Conditional blocks: you can do something like ... {#if Property is not null} ({Property}){#end} ...