mrall
February 7, 2020, 7:32pm
1
Hello,
I’m using Servicestack (.Core) and it’s connection to Serilog. Is there a way to automatically enrich all Log-Entries with things like SessionId, UserId, etc… The existing serilog-enrichers will not work due servicestack uses it’s own session and user handling.
kind regards
Not sure if @mythz has a better answer, but I made a custom IRequestLogger
plugin, and pushed whatever properties I needed using ILog.PushProperty
mrall
February 9, 2020, 9:30pm
3
Hey @jrodrigu ,
thanks for your suggestion, I’ll have a look at that.
mythz
February 10, 2020, 10:01am
4
There’s an example for a Serilog enricher answered on StackOverflow at:
servicestack
If your AppHost supports accessing the Request context via a singleton you can access it from:
HostContext.GetCurrentRequest()
However it’s disabled by default in .NET Core and requires registering a HttpContextAccessor
:
It’s a static handler to be initialized once on Startup, it doesn’t have access to any per-request context itself, only if the request context was made statically available on the HTTP request worker thread that invokes the callback.
Historically this is only possible in classic ASP .NET Framework (via its HttpContext.Current singleton) which you can access from:
var req = HostContext.AppHost.TryGetCurrentRequest();
It’s disabled in .NET Core by default due to performance, but you can opt-in …