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

Install the NuGet package:

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

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

Configure

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

Verify

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.

Xamarin Options

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

DisableNativeIntegration

Disable the native event processor for Android,iOS,UWP

DisableOfflineCaching

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.

AttachScreenshots

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

Xamarin Forms Options

DisableXamarinWarningsBreadcrumbs

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

Troubleshooting

For information about Troubleshooting, please visit the troubleshooting page.

Samples

  • An example using Xamarin Forms and most of the SDK features. (Android, iOS, UWP)