• /
  • EnglishEspañol日本語한국어Português
  • EntrarComeçar agora

Monitor your Xamarin mobile app

Our New Relic Xamarin agent monitors your Xamarin mobile app and provides deep insights into your app's performance, errors, and user experience. Once you install and configure the Xamarin agent, you'll be able to:

  • Capture C# errors: Identify and fix problems quickly.
  • Track network requests: See how your app interacts with the backend.
  • Use distributed tracing: Drill down into handled exceptions and find the root cause.
  • Create custom events and metrics: Understand how your users interact with your app.
Summary view of a Xamarin app in New Relic

one.newrelic.com > All capabilities > Mobile > (select an app) > Summary: View Xamarin data, track HTTP requests and errors, and monitor how your app is performing over time.

(Recommended) Guided installation

To install the Xamarin agent, follow our guided install, located directly in the UI.

Manual installation

If you need to install the agent manually, follow these steps:

Review the requirements

Before you install our Xamarin agent, make sure your app meets these version requirements:

  • Xamarin.Android 8.0 or higher
  • Xamarin.iOS 10.14 or higher
  • For Android-native apps, use Android API 24 or higher
  • For iOS-native apps, use iOS 10

Add the Xamarin agent to your project

First, you'll need to add our agent, a NuGet package, to your Xamarin project:

  1. Open your Xamarin solution, select the Xamarin.Forms project you want to add the agent to, and open its context menu.
  2. Click Add > Add NuGet packages, then select NewRelic.Xamarin.Plugin. You'll also need to add our iOS agent binding to your Xamarin.iOS project:
  3. Select the Xamarin.iOS project you want to add the agent to, and open its context menu.
  4. Add > Add NuGet packages, then select NewRelic.Xamarin.iOS.Binding.

Copy your application token from the UI

The application token is used for New Relic to authenticate your Xamarin app's data. To view and copy your application token in the New Relic UI:

  1. Go to one.newrelic.com, click Integrations & Agents, then click Mobile.

  2. Select your Xamarin app.

  3. Go to Settings > Application and copy the displayed Application token.

    You'll add this application token in the next step.

Add our agent configuration file to App.xaml.cs

In your project's App.xaml.cs file, add the following code:

using NewRelic.Xamarin.Plugin;
...
public App ()
{
InitializeComponent();
MainPage = new MainPage();
Application.Current.PageAppearing += OnPageAppearing;
Application.Current.PageDisappearing += PageDisappearing;
CrossNewRelicClient.Current.HandleUncaughtException();
CrossNewRelicClient.Current.TrackShellNavigatedEvents();
// Set optional agent configuration
// Options are: crashReportingEnabled, loggingEnabled, logLevel, collectorAddress,
// crashCollectorAddress, analyticsEventEnabled, networkErrorRequestEnabled,
// networkRequestEnabled, interactionTracingEnabled, webViewInstrumentation, fedRampEnabled,
// offlineStorageEnabled, newEventSystemEnabled, backgroundReportingEnabled
// AgentStartConfiguration agentConfig = new AgentStartConfiguration(crashReportingEnabled:false);
if (Device.RuntimePlatform == Device.Android)
{
CrossNewRelicClient.Current.Start("YOUR_APP_TOKEN");
// Start with optional agent configuration
// CrossNewRelicClient.Current.Start("YOUR_APP_TOKEN", agentConfig);
}
else if (Device.RuntimePlatform == Device.iOS)
{
CrossNewRelicClient.Current.Start("YOUR_APP_TOKEN");
// Start with optional agent configuration
// CrossNewRelicClient.Current.Start("YOUR_APP_TOKEN", agentConfig);
}
}

Make sure you paste your application token(s) into appToken = "" in the code above. If you deployed your hybrid app to both iOS and Android platforms, you'll need to add two separate tokens: one for iOS and one for Android.

(Android only) Add permissions

If you have an Android-native app, you'll need to add INTERNET and ACCESS_NETWORK_STATE permissions in your Platforms/Android/AndroidManifest.xml file:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

Customize the agent instrumentation

Need to customize your agent instrumentation? Our public mobile SDK API methods let you collect custom data, configure default settings, and more.

The following customizations are available for the Xamarin agent.

If you want to...

Use this method

Record breadcrumbs to track app activity that may be helpful for troubleshooting crashes.

Record breadcrumbs

Track a method as an interaction.

Start interactions

Stop interactions

Record custom metrics.

Record custom metrics

Record handled exceptions.

Record handled exceptions

Record custom attributes and events.

There are several ways to report custom attributes and events:

Track custom network requests and failures.

Track HTTP requests

Track failing HTTP requests

Shut down the agent.

Shut down the agent

Enable/disable default mobile monitoring settings.

Enable/disable monitoring features

Run a test crash report.

Test crash reporting

Troubleshoot HTTP errors

Missing HTTP data in the UI?

After installing the .NET MAUI agent, wait at least 5 minutes. If No HTTP data appears: on the HTTP errors and HTTP requests UI pages, make sure you used HttpMessageHandler in HttpClient.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.