.NET for iOS, macOS, and Mac Catalyst

Learn about Sentry's .NET integration with .NET for iOS, macOS, and Mac Catalyst

Sentry supports .NET for iOS, macOS, and Mac Catalyst directly from the Sentry NuGet package.

Add the Sentry dependency to your .NET for iOS, macOS, and/or Mac Catalyst application:

Copied
dotnet add package Sentry -v 5.10.0

In your AppDelegate.cs file, call SentrySdk.Init in the FinishedLaunching event and include any options you would like to set. The Dsn is the only required parameter.

Copied
[Register("AppDelegate")]
public class AppDelegate : UIApplicationDelegate
{
    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        // Init the Sentry SDK
        SentrySdk.Init(options =>
        {
            options.Dsn = "https://examplePublicKey@o0.ingest.sentry.io/0";
            options.SendDefaultPii = true; // adds the user's IP address automatically
#if DEBUG
            // Log debug information about the Sentry SDK
            options.Debug = true;
#endif

            // All the native iOS SDK options are available below
            // https://docs.sentry.io/platforms/apple/guides/ios/configuration/
            // Enable Native iOS SDK App Hangs detection
            options.Native.EnableAppHangTracking = true;

            options.SetBeforeSend(evt =>
            {
                if (evt.Exception?.Message.Contains("Something you don't care want logged?") ?? false)
                {
                    return null; // return null to filter out event
                }
                // or add additional data
                evt.SetTag("dotnet-iOS-Native-Before", "Hello World");
                return evt;
            });

            options.OnCrashedLastRun = e =>
            {
                Console.WriteLine(e);
            };
        });
    }
}

The .NET for iOS, macOS, and Mac Catalyst integration is part of Sentry. Please refer to the documentation for that package for information about platform agnostic options.

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.

Copied
try
{
    throw null;
}
catch (Exception ex)
{
    SentrySdk.CaptureException(ex);
}
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").