How to create an optional property in a Serilog output template?

I am trying to create a global output template for Serilog messages, in the following format:

{Timestamp:yyyy-MM-dd HH:mm:ss,fff} [{ComponentName}, {ApplicationName}, {ThreadId}] {Level} ({ErrorId}): {Message} {Exception}

The problem I am facing is that some messages do not contain error or exception identifiers or ThreadIds. So, when this happens, I get a message with a lot of characters that add noise to the log message, for example,

2015-06-24 15:11:03,234 [Component, MyApp, ] Info (): This is a message that I'm writing

Is it possible that Serilog supports optional parameters in the message template?

+4
source share
1 answer

I use Serilog in my application, and, as you noticed, the “missing” fields will “disappear”, as you noticed, but formatting the characters around these placeholders does not.

, , , ( ) , .

Serilog (logger.Debug, logger.Warning, logger.Information ..), , ( ), , . , .

0

All Articles