i want to build some logger providerand have option to get username in ithow to do that?
i use some external OIDCso in api i have only
builder.Services.AddAuthentication("Bearer").AddJwtBearer("Bearer", options =>{ options.Authority = "https://xxxx/auth/realms/dev"; options.TokenValidationParameters.ValidateAudience = false;});so now
builder.Services.AddScoped<ILoggerProvider,DbLoggerProvider>();and if i want to get in ctor
public DbLoggerProvider(IOptions<DbLoggerProvider> options, AuthenticationStateProvider asp)then it crash on build with message that
System.AggregateException Message=Some services are not able to be constructed Source=Microsoft.Extensions.DependencyInjection StackTrace: at Microsoft.Extensions.DependencyInjection.ServiceProvider. .ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)at Microsoft.Extensions.DependencyInjection.ServiceCollection ContainerBuilderExtensions.BuildServiceProvider (IServiceCollection services, ServiceProviderOptions options)at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()at Program.<Main>$(String[] args) in D:\x\Server\Program.cs:line 153This exception was originally thrown at this call stack:[External Code]Inner Exception 1:InvalidOperationException: Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostApplicationLifetime Lifetime: Singleton ImplementationType: Microsoft.Extensions.Hosting.Internal.ApplicationLifetime': Unable to resolve service for type 'Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider' while attempting to activate 'x.Server.Core.Providers.DbLoggerProvider'.Inner Exception 2:InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Components.Authorization. AuthenticationStateProvider' while attempting to activate 'x.Server.Core.Providers.DbLoggerProvider'.in controllers i get username like
string login = User.Claims.Where(p => p.Type == "preferred_username").First().Value;how can i have this login in loggerprovider?how controller is getting this user object if nor from AuthenticationStateProvider ?
thanks and regards