Search code examples
c#serilog

Serilog show the property name in the output


If I have this:

logger.Information("this is a message with {property_name}", "value");

Ho do I output this:

this is a message with property_name = value

instead of:

this is a message with value

Solution

  • The display output of log messages written via Serilog is done by the formatter used by the Sink that you are writing to. Each sink can use a different formatter and can represent outputs differently.

    What you are asking for is not something that the default formatters can do, so you would have to write your own custom text formatter, and then tell the Sink to use your formatter instead of the default one.

    Formatting Output

    Serilog provides several output formatting mechanisms.

    • Formatting plain text
    • Formatting JSON
    • Custom text formatters