Xamarin

Sentry's .NET SDK works with Xamarin applications through the Sentry Xamarin NuGet package and Xamarin Forms with the Sentry Xamarin Forms NuGet package.

The SDK is compatible with the following versions or higher:

  • Xamarin.Android 9.0
  • Xamarin.iOS 10.14
  • Universal Windows Platform 10.0.16299
  • Tizen 4.0

Install the NuGet package:

Copied
# For Xamarin.Forms
Install-Package Sentry.Xamarin.Forms -Version 2.0.0

# If you are not using Xamarin.Forms, but only Xamarin:
Install-Package Sentry.Xamarin -Version 2.0.0

After you’ve completed setting up a project in Sentry, Sentry will give you a value which we call a DSN or Data Source Name. It looks a lot like a standard URL, but it’s just a representation of the configuration required by the Sentry SDKs. It consists of a few pieces, including the protocol, public key, the server address, and the project identifier.

You should initialize the SDK as early as possible, for an example, the start of OnCreate on MainActivity for Android, and, the top of FinishedLaunching on AppDelegate for iOS).

Copied
using Sentry;

SentryXamarin.Init(o =>
{
    o.AddXamarinFormsIntegration();
    // 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 TracesSampleRate to 1.0 to capture 100%
    // of transactions for performance monitoring.
    // We recommend adjusting this value in production
    o.TracesSampleRate = 1.0;
});
// App code

Great! Now that you’ve completed setting up the SDK, maybe you want to quickly test out how Sentry works. Start by capturing an exception:

You can verify Sentry is capturing unhandled exceptions by raising an exception. For example, you can use the following snippet to raise a NullReferenceException:

Copied
throw null;

All you need to do is to initialize the SDK with SentryXamarin.Init, you will not need any additional changes to get the SDK ready to go.

The SDK automatically handles AppDomain.UnhandledException and Application.UnhandledException, so you'll not need to worry about trying to Catch Unhandled Exceptions.

The following options are only going to be valid during the SDK initialization.

Disable the native event processor for Android,iOS,UWP

By calling it, the SDK will not automatically Cache your events and they might be lost if a hard crash happens or no connectivity is available during the transport of the event.

Automatically attaches a screenshot of the app at the time of the event capture. By default, it is set to false.

Disables the automatic Logging of internal Warnings that comes from Xamarin Forms.

For information about Troubleshooting, please visit the troubleshooting page.

  • An example using Xamarin Forms and most of the SDK features. (Android, iOS, UWP)
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").