3

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.

jnovo
  • 5,659
  • 2
  • 38
  • 56
Astemir Almov
  • 396
  • 2
  • 16

1 Answers1

1

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.

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101