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 1.0.3

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

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
SentryXamarin.Init(o =>
{
	  o.AddXamarinFormsIntegration();
    o.Dsn = "https://examplePublicKey@o0.ingest.sentry.io/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
SentryXamarin.Init("https://examplePublicKey@o0.ingest.sentry.io/0");
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.

Xamarin Forms Options

DisableXamarinWarningsBreadcrumbs

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

Samples

  • An example using Xamarin Forms and most of the SDK features. (Android, iOS, UWP)
You can edit this page on GitHub.