Set user context in raven-csharp

How do you set the user context (specifically current logged in user) in raven-csharp? Easy enough with the Javascript SDK (see, but doesn’t appear to have the same option for raven-csharp that I can see (although haven’t dug around in the source).

1 Like

I’m also interested in this case. Have you already found any solution for it?

Unfortunately no response and no solution. Although helpful to see I’m not the only one not able to figure it out.

You have to implement ISentryUserFactory, like this for example:

public class SentryMepUserFactrory : ISentryUserFactory
    private readonly IHttpContextAccessor httpContextAccessor;

    public SentryMepUserFactrory(IHttpContextAccessor httpContextAccessor)
        this.httpContextAccessor = httpContextAccessor;

    public SentryUser Create()
        return new SentryUser(httpContextAccessor.HttpContext?.User?.Identity ?? new AnonymousIdentity());

and inject it into your client:

client = new RavenClient(new Dsn(dsn), sentryUserFactory:new SentryMepUserFactrory(httpContextAccessor))