Universal Windows Platform

Sentry's .NET SDK works with Universal Windows platform applications through the Sentry NuGet package.

Configuration

In addition to initializing the SDK with SentrySdk.Init, you must configure the UWP specific error handler.

Copied
using Sentry;
using System.Runtime.ExceptionServices;
using System.Security;
using Windows.UI.Xaml;
using UnhandledExceptionEventArgs = Windows.UI.Xaml.UnhandledExceptionEventArgs;

sealed partial class App : Application
{
    public App()
    {
        SentrySdk.Init(o => 
        {
            // Tells which project in Sentry to send events to:
            o.Dsn = "https://examplePublicKey@o0.ingest.sentry.io/0";
            // When configuring for the first time, to see what the SDK is doing:
            o.Debug = true;
            // Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
            // We recommend adjusting this value in production.
            o.TracesSampleRate = 1.0;
        });
        Current.UnhandledException += ExceptionHandler;
    }

    [HandleProcessCorruptedStateExceptions, SecurityCritical]
    internal void ExceptionHandler(object sender, UnhandledExceptionEventArgs e)
    {
        // We need to hold the reference, because the Exception property is cleared when accessed.
        var exception = e.Exception;
        if (exception != null)
        {
            // Tells Sentry this was an Unhandled Exception
            exception.Data[Mechanism.HandledKey] = false;
            exception.Data[Mechanism.MechanismKey] = "Application.UnhandledException";
            SentrySdk.CaptureException(exception);
            // Make sure the event is flushed to disk or to Sentry
            SentrySdk.FlushAsync(TimeSpan.FromSeconds(3)).Wait();
        }
    }

}