I'm pushing values to the Serilog LogContext
in a middleware class of a .NET Core web app:-
using LogContext.PushProperty("MyAct", "some clever joke") ...
Is it possible to read the value for MyAct
property in a downstream class? I don't see anything promising on the LogContext class - seems like a write only entity, but maybe I am missing something?
Serilog does not provide for you to Just Read the values from the LogContext
.
Normally the PushProperty
stashes it, and Enrich.FromLogContext
is charged with grabbing the contextual information that will accompany the destructured message and tokens as the logging call is capturing them into the LogEvent
that'll then be passed to the chain of sinks.
Really this begs the question: why do you feel you need to do this?
Actually answering the question: It is possible the underlying APIs are exposed in a usable fashion though; I'd go to https://github.com/serilog/serilog - the LogContext
impl and tests are all in that core repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With