dotnet / dotnet/aspnetcore

[Blazor Server] Ability to have scoped logger

Open
#25,442 8 comments 5 reactions 0 assignees View on GitHub
affected-very-few area-blazor enhancement feature-blazor-server feature-blazor-server-experience severity-blocking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

Hello guys, In my blazor server app i would like to Inject some scoped services in my logger to trace some client information like circuitId (or other scoped data which allow me to identify the client). Otherwise it will be a mess in my logs, I will not be able to attach an exception to a specific client.

I already read here its a bad idea to have a scoped logger, however i really need this features, so i try with this :
````
services.AddScoped();
services.Add(ServiceDescriptor.Scoped(typeof(ILogger<>), typeof(MyLogger<>)));
````
However i have this error at startup
````
Cannot resolve scoped service 'Microsoft.Extensions.Logging.ILogger`1[Microsoft.AspNetCore.Hosting.WebHost]' from root provider.'
````
So the question, is it something can be achieved now ? (even if its dirty) or there is no way i can retrieve scoped information from the logger ?

thanks !

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.