Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to use ProtectedSessionStorage with a Serilog enricher?

$
0
0

I have an enricher that needs to use the protected session storage to get the user info:

public class SessionEnricher : ILogEventEnricher{    private const string UsernamePropertyName = "Username";    private readonly ProtectedSessionStorage sessionStorage;    public SessionEnricher(        ProtectedSessionStorage sessionStorage)    {        this.sessionStorage = sessionStorage;    }    public async void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)    {        var userName = await sessionStorage.GetItemAsync<string>("UsernameKey");        var userNameProperty = propertyFactory.CreateProperty(UsernamePropertyName, userName);        logEvent.AddPropertyIfAbsent(userNameProperty);    }}

And the enricher is set up as a transient service and added to the serilog configuration on startup.

However I am getting:

Cannot resolve 'Serilog.Enrichers.UserEnricher' from root provider because it requires scoped service 'Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage.ProtectedSessionStorage'.

Is accessing the session storage even possible in such a case?


Viewing all articles
Browse latest Browse all 4839

Trending Articles