How to use ILogger.BeginScope in Blazor Server for the entire activity? #55949
Replies: 1 comment 1 reply
-
Depending on the logger you could access scoped services by the use of async-locals initialized within For example see https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-8.0#access-server-side-blazor-services-from-a-different-di-scope Using Serilog for example you then would implement an And you really should use |
Beta Was this translation helpful? Give feedback.
-
In a standard request/response app with AspNet.Core, it was easy to add informations in the request context so that every single log entry could have access to them automatically. For exemple, if I need that all my log entries have the FormId that he is presently editing, I just had to create a new Middleware that use ILogger.BeginScope to achieve that and register the middleware at the beginning of the pipeline.
How can we achieve the same thing in Blazor? The only way i've found is with NET 8 and the new CreateInboundActivityHandler that you can override in the CircuitHandler. Is it the way to go? Because depending of the object that you inject, the information inside is not always up-to-date. For exemple, NavigationManager.Uri doesn't have the new value yet and it return the uri where you come from and not the current one.
For exemple,
Beta Was this translation helpful? Give feedback.
All reactions