Skip to content

Enrich Serilog log events with properties from LogEvent.MessageTemplate.Text

Notifications You must be signed in to change notification settings

bduman/serilog-enrichers-message-template

Repository files navigation

Serilog.Enrichers.MessageTemplate

Nuget Push Nuget

Enriches Serilog events with log event's message template.

To use the enricher, first install the NuGet package:

Install-Package Serilog.Enrichers.MessageTemplate

Then, apply the enricher to your LoggerConfiguration:

Log.Logger = new LoggerConfiguration()
    .Enrich.WithMessageTemplate()
    // ...other configuration...
    .CreateLogger();

The WithMessageTemplate() enricher will add a MessageTemplate property to produced events.

What's message template ?

When you log any message to your sinks, as below, the message template is given as the first argument.

Log.Information("Single log info"); // non-structural
Log.Information("Single log info {@test}", "test"); // or structural

How can i use it ?

Add {MessageTemplate} to your sink's output template.

..
.WriteTo.Console(outputTemplate:
        "[{Timestamp:HH:mm:ss} {Level:u3}] {MessageTemplate} {Message:lj}{NewLine}{Exception}")
.CreateLogger();

About

Enrich Serilog log events with properties from LogEvent.MessageTemplate.Text

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages