Serilog - is it possible not to display property "MessageTemplate" when logging to file?

Viewed 371

I have configured a logger using Serilog

_logger = new LoggerConfiguration()
        .WriteTo.File(new JsonFormatter(), configuration["loggerPath"],
         rollingInterval:RollingInterval.Day)
        .CreateLogger()

Then I try to log sample information with method:

public void Info(AdditionalInfo additionalInfo)
    {
        _logger.Information("{EventCategory} {Process}", additionalInfo.EventCategory, additionalInfo.Process);
    }

The information is logged and I am satisisfied. However, I do not think I need MessageTemplate property in my log. Also it is additional information to store. Is it possible to tell Serilog not to display it? If not, why is it necessary?

{"Timestamp":"2020-08-11T17:17:01.9862562+02:00","Level":"Information","MessageTemplate":"{EventCategory} {Process}",
"Properties":{"EventCategory":"Category","Process":"Tests"}}
1 Answers

To customize the output, you'll need to use a different formatter (instead of the JsonFormatter you're using). You can also create your own formatter.

It's all explained in the documentation:

Serilog: Formatting Output

Related