Skip to content

[Blazor Server] Ability to have scoped logger #25442

@julienGrd

Description

@julienGrd

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<ILogger, MyLogger>();
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 !

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-very-fewThis issue impacts very few customersarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-serverfeature-blazor-server-experienceIssues that make Blazor server experience different of Web assembly or Desktopseverity-blockingThis label is used by an internal tool

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions