Search code examples
c#serilog

What do @ and $ do in a Serilog message template parameter?


I found some code with log parameters that use the @ sign in front of the name.
logger.LogError(ex, "Failed to add {@data}", jsonData)

I'm having trouble finding the docs for what this does exactly. The Serilog doc says this:

Property names may be prefixed with an optional operator, @ or $, to control how the property is serialised

But it doesn't say what that will do. How does {@data} differ from {data} in a log message template?


Solution

  • There is some documentation on these operators here (also accessible via serilog.net).

    • @ is the destructuring operator
    • $ is the stringification operator