I'm using LoggerMessage logging in my application. I want to use structured logging like below. But I don't see a way. Is this possible in LoggerMessage ?
logger.LogInformation("Test {id}",id)
Update:
To make it clear, I like to achieve something similar to ILogger . Using single logger instance we can log any message with any number of placeholders.
I like to achieve something similar to ILogger. Using single logger instance we can log any message with any number of placeholders.
Then use ILogger.
LoggerMessage sacrifices usability for performance. It does this by pre-parsing the message template so you don't have to incur the cost of parsing whenever you log that message. The upshot of this is that you have to use a separate LoggerMessage instance for each message template.
Logger extension methods must parse the message template (named format string) every time a log message is written. LoggerMessage only requires parsing a template once when the message is defined.
-- https://learn.microsoft.com/en-us/dotnet/core/extensions/high-performance-logging
If you're okay with that trade-off, use LoggerMessage the way it's documented. Or, better yet, use the LoggerMessage attribute for precompiled message templates.
Otherwise, use the ILogger extension methods.