Log properties not recording in Serilog

364 views Asked by At

For exmple, I have function doSomething(string a, string b, string c). And I want to log function executing. I want do something like this:

Logger.Debug("Method doSomething executed", a, b, c)

to avoid writing parameters in message beacause strings can be very long. This functionality is similar to the .Enrich.WithProperty("PropertyName", Value). But i can't do this in Logger constructor. Logs writes to SEQ.

1

There are 1 answers

0
Nicholas Blumhardt On

ForContext() can do this:

var enriched = Log.ForContext("A", a)
                  .ForContext("B", b)
                  .ForContext("C", c);

enriched.Debug("Method doSomething executed");

All events logged through enriched will have the properties A, B and C attached.