Using App Center Diagnostics & Analytics with .NET MAUI

App Center is alive! With a pre-release version of the App Center packages, they’re showing that they’re adding .NET MAUI support. Gerald Versluis posted a great video with an overview of the capabilities of this pre-release. This post will be heavily inspired by his video and will serve as a written guide for how you can collect diagnostics and analytics for your .NET MAUI application. I recommend watching his video for an excellent run-through.

Register your application

You will first have to register your application in the App Center portal. This is a bit different depending on your target platform. I will show you how you can do this for Windows, iOS and Android. Note that the portal hasn’t been updated yet for MAUI so we’ll have to select the options that are the closest equivalents.

Windows

Click “Add new app” and Select “Windows” and “UWP”.

Selections for creating the .NET MAUI Windows app in App Center.

iOS

Select “iOS” and “Xamarin”.

Selections for creating the .NET MAUI iOS app in App Center.

Android

Select “Android” and “Xamarin”.

Selections for creating the .NET MAUI Android app in App Center.

Install the package

In your .NET MAUI application, open the NuGet Package Manager and search for Microsoft.AppCenter. Remember to check the “pre-release” checkbox. Go ahead and install both the version 5.0.0-preview.1 of Microsoft.AppCenter.Analytics and Microsoft.AppCenter.Crashes.

The App Center packages in NuGet Package Manager.

Initialization

We’ll do the initialization in MauiProgram.cs. Add the following line right before the return statement:

  AppCenter.Start("windowsdesktop={Your Windows App secret here};" +
                "android={Your Android App secret here};" +
                "ios={Your iOS App secret here};",
                typeof(Analytics), typeof(Crashes));

Replace Your Windows App secret here with the Windows app secret from App Center. You can find this by navigating to the Windows app in App Center and scrolling down to “Integrate app secret” in the “Overview” page.

App secret.

Do the same for your Android and iOS app and replace them respectively.

That’s all! Now you can start your app and you should pretty instantly see things popping up under Analytics.

If you want to test out crashes (Diagnostics) as well, add this line in f.ex. a button event handler or just in your startup code:

Crashes.GenerateTestCrash();

Note that you need to start your app again after the crash so that the crash report gets sent up to App Center.

I also have a GitHub sample for this, if you want to check it out.

1 thought on “Using App Center Diagnostics & Analytics with .NET MAUI”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.