Nuestro agente New Relic .NET MAUI monitorea su aplicación móvil .NET MAUI y proporciona información profunda y valiosa sobre el rendimiento, los errores y la experiencia del usuario de su aplicación. Una vez que instale y configure el agente .NET MAUI, podrá:
- Capture C# errors: Identifique y solucione problemas rápidamente.
- Track network requests: Vea cómo interactúa su aplicación con el backend.
- Use distributed tracing: Profundice en las excepciones manejadas y encuentre la causa raíz.
- Create custom events and metrics: Comprenda cómo interactúa su usuario con su aplicación.

one.newrelic.com > All capabilities > Mobile > (select your .NET MAUI app) > Summary: vea datos de .NET MAUI, realice un seguimiento de las solicitudes y errores HTTP y monitor el rendimiento de su aplicación a lo largo del tiempo.
(Recomendado) Instalación guiada
Para instalar el agente .NET MAUI, siga nuestra instalación guiada, ubicada directamente en la UI.
Instalación manual
Si necesita instalar el agente manualmente, siga estos pasos:
Revisa los requisitos
Antes de instalar nuestro agente .NET MAUI, asegúrese de que su aplicación cumpla con estos requisitos de versión:
- .NET versión 7.0 o superior
- Para aplicaciones nativas de Android: Android 7 (API 24) o superior
- Para aplicaciones nativas de iOS:
- iOS 16 o superior, utilizando la última versión de Xcode
Agregue el agente .NET MAUI a su proyecto
Primero, deberá agregar nuestro agente, un paquete NuGet, a su proyecto MAUI:
- Abra su solución .NET MAUI, seleccione el proyecto al que desea agregar el agente y abra su menú contextual.
- Haga clic en Add > Add NuGet packages y luego seleccione
NewRelic.MAUI.Plugin.
Copie el token de su aplicación desde la UI
The application token is used for New Relic to authenticate your .NET MAUI app's data.
To view and copy your application token in the New Relic UI:
Vaya a one.newrelic.com, haga clic en Integrations & Agents y luego haga clic en Mobile.
Seleccione su aplicación .NET MAUI.
Vaya a Settings > Application y copie el Application token mostrado.
Agregará este token de aplicación en el siguiente paso.
Agregue nuestro archivo de configuración del agente a su proyecto .NET MAUI
En su proyecto, abra MauiProgram.cs y agregue el siguiente código:
using NewRelic.MAUI.Plugin;
... public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiAppApp_()_ .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); });
builder.ConfigureLifecycleEvents(AppLifecycle => { #if ANDROID AppLifecycle.AddAndroid(android => android .OnCreate((activity, savedInstanceState) => StartNewRelic())); #endif
#if IOS AppLifecycle.AddiOS(iOS => iOS.WillFinishLaunching((_,__) => { StartNewRelic(); return false; })); #endif });
return builder.Build(); }
private static void StartNewRelic() { CrossNewRelic.Current.HandleUncaughtException(); // 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 (DeviceInfo.Current.Platform == DevicePlatform.Android) { CrossNewRelic.Current.Start("APP_TOKEN_HERE"); // Start with optional agent configuration // CrossNewRelic.Current.Start("APP_TOKEN_HERE", agentConfig); } else if (DeviceInfo.Current.Platform == DevicePlatform.iOS) { CrossNewRelic.Current.Start("APP_TOKEN_HERE"); // Start with optional agent configuration // CrossNewRelic.Current.Start("APP_TOKEN_HERE", agentConfig); } }Asegúrese de pegar token de su aplicación en appToken = "<APP-TOKEN-HERE>" en el código anterior. Si implementa su aplicación híbrida en la plataforma iOS y Android, deberá agregar dos tokens separados: uno para iOS y otro para Android.
Evento de seguimiento de pantalla
The .NET MAUI mobile plugin allows you to track navigation events within the .NET MAUI Shell. There are two ways to initialize this depending on your app's startup timing in App.xaml.cs.
Option 1: In the App Constructor You can call the tracking method directly in the constructor immediately after setting the MainPage.
public App(){ InitializeComponent(); MainPage = new AppShell(); CrossNewRelic.Current.TrackShellNavigatedEvents();}Option 2: In the OnStart Method (Recommended for timing/NullReferenceException issues) If your application shell is not fully initialized during the constructor execution, calling the navigation tracker may result in a System.NullReferenceException. To avoid this, move the call into the MAUI OnStart() lifecycle method:
public App(){ InitializeComponent(); MainPage = new AppShell();}
protected override void OnStart(){ base.OnStart(); CrossNewRelic.Current.TrackShellNavigatedEvents();}Se recomienda llamar a este método al iniciar el agente. Estos eventos sólo se registrarán una vez completada la navegación. Puede encontrar estos datos a través del explorador de datos en MobileBreadcrumb (bajo el nombre ShellNavigated) o mediante una consulta NRQL:
SELECT * FROM MobileBreadcrumb WHERE name = 'ShellNavigated' SINCE 24 HOURS AGOLa ruta de navegación contendrá tres atributos:
Current: El URI de la página actual.Source: El tipo de navegación que ocurrió.Previous: El URI de la página anterior. Esto no existirá si la página anterior era nula.
Personalizar la instrumentación del agente.
¿Necesitas personalizar tu instrumentación del agente? Nuestros métodos públicos de API de SDK móvil le permiten recopilar datos personalizados, configurar ajustes predeterminados y más.
Las siguientes personalizaciones están disponibles para el agente .NET MAUI.
Si quieres... | Utilice este método |
|---|---|
Registre la ruta de navegación para rastrear la actividad de la aplicación que puede ser útil para resolver problemas. | |
Seguimiento de un método como una interacción. | |
Registro métrico personalizado. | |
Registro de excepciones manejadas. | |
Grabar atributo personalizado y evento. | Hay varias formas de reportar atributo personalizado y evento:
|
Realice un seguimiento de las solicitudes y fallas de la red personalizada. | Seguimiento de solicitudes HTTP |
Apague el agente. | |
Activa/desactiva la configuración predeterminada de monitoreo de móviles. | |
Ejecute un informe de fallo de prueba. |
Resolución de problemas
Solucionar errores HTTP
¿Faltan datos HTTP en la UI?
Después de instalar el agente .NET MAUI, espere al menos 5 minutos. Si no aparecen datos HTTP en las páginas UI de errores HTTP y solicitudes HTTP, asegúrese de haber utilizado HttpMessageHandler en HttpClient.
Faltan datos de rastreo distribuido en la UI
El rastreo distribuido no funciona cuando se emplean métodos estáticos para informar datos HTTP. Para habilitar el rastreo distribuido, debe emplear HttpMessageHandler con HttpClient.
HttpClient myClient = new HttpClient(CrossNewRelic.Current.GetHttpMessageHandler());
var response = await myClient.GetAsync(new Uri("https://jsonplaceholder.typicode.com/todos/1")); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); } else { Console.WriteLine("Http request failed"); }App crashes with TrackShellNavigatedEvents
If you experience a System.NullReferenceException when calling CrossNewRelic.Current.TrackShellNavigatedEvents() in the App() constructor, it is likely because the application shell is not fully bootstrapped yet. To resolve this, move the call out of the constructor and into the MAUI OnStart() lifecycle method within your App.xaml.cs file (see the Screen tracking events section for code examples).