Can't get it to work with .NET Framework 4.8 project

I’ve followed the instructions on how to set up Sentry on a .NET Framework 4.8 project (in my case, it’s a WCF application, so the setup should be similar to the one in this GitHub repo), but I can’t get it to send anything to Sentry.

I put the initialization code in Application_BeginRequest because putting it in Application_Start caused _sentry to always be null. This is what I have:

public class Global : HttpApplication
    private IDisposable _sentry;

    protected void Application_BeginRequest()
        if (_sentry == null)
            _sentry = SentrySdk.Init(o =>
                o.Dsn = "";
                o.Debug = true;
                o.TracesSampleRate = 1.0;

        var id = SentrySdk.CaptureMessage("Something went wrong");

        // etc

_sentry and id are not null, but Sentry doesn’t receive anything.

Sentry.Init should be called on Application_Start which will run once. When the process starts.

Application_BeginRequest runs for each request, concurrently so the SDK will be getting reinitialized over and over again throwing away previous data collected in one request when another one starts soon after.

Since this event lifecycle is owned by .NET (IIS, AppPool) there’s probably something odd going on if _sentry is null. If you’ve assigned a value to it on Application_Start, it couldn’t be null when Application_BeginRequest runs unless the IIS event lifecycle is broken.

Thank you for your response. While it truly is strange that _sentry is null when instantiated in Application_Start, and I plan on looking into that, I would expect the example I gave to send a message to Sentry, but it does not. Do you have any insight on why that might be?

I see you’re setting Debug=true but since ASP.NET/IIS doesn’t have a console you can see the logs, you need to change the logger so you can see it in Visual Studio.

The docs cover how to do that here: Diagnostic Logger for .NET | Sentry Documentation

The SDK should log out what’s happening internally. Often when folks using IIS can’ capture events the issue is related to the server requiring a proxy to access the Internet.
This situation (and other common issues) are clarified on the troubleshooting page: Troubleshooting for ASP.NET | Sentry Documentation