Xamarin.Mac exception reporting with Raygun + 64-bit support

| 5 min. (858 words)

Today we are pleased to announce that Raygun can now be used in your Xamarin.Mac projects. When your application has been released, it’s important to know how well it’s doing exception-wise, without needing to rely on customers letting you know every single time it crashes.

By integrating Raygun into your Xamarin.Mac applications, you’ll get exception reports sent to your Raygun.io dashboard as soon as they occur. Reports include as much information about the exception and environment as possible to help you track down and solve each bug. This information includes the stack trace, exception message, OS version, machine architecture, application version and more. As with all Raygun providers, exception reports will be treated with intelligent grouping, smart notifications, flexible searching/filtering and application health charts.

Xamarin.Mac 2.0 Beta support (Unified APIs with 64-bit support)

As you may know, Xamarin has recently released Xamarin.Mac 1.10 in their beta channel which uses a preview of the new Unified APIs including 64-bit framework support. This is leading up to the release of the Xamarin.Mac 2.xx series. If you’ve been tinkering around with this, and would like to use Raygun, you’ll be glad to hear that we support this too! Everything in this blog post applies in exactly the same way when using Raygun in classic Xamarin.Mac projects and the new Xamarin.Mac unified API projects. Simply use the appropriate Raygun4Net dll in your project as mentioned below.

How to use

Xamarin.Mac support is included as part of the Raygun4Net provider. To get this, download the .zip of assemblies from the latest release listed on Github (click the green button). Unzip this and get the Mindscape.Raygun4Net.Xamarin.Mac.dll (Or Mac2Beta.dll) from the root folder. Copy and reference this dll into your project.

Now, in the main entry point of your application, call the static RaygunClient.Attach method and pass in your application API key. You get an API key when you create a new application in your Raygun.io account.

static void Main (string[] args)
{
  RaygunClient.Attach("YOUR_APP_API_KEY");

  NSApplication.Init();
  NSApplication.Main(args);
}

And that’s all that you need to do to get Raygun4Net automatically sending unhandled exception information to your Raygun.io dashboard. At any point after you’ve called the Attach method, you can use RaygunClient.Current to get the active RaygunClient instance to manually send exceptions or set up additional options.

Manual sending

The above steps will give you awareness of all unhandled exceptions occurring in your application, but sometimes you may also want to send exceptions that you are handling in a try/catch block. These exceptions won’t crash the application, but may point out things that can be improved. To send exceptions manually, simply call one of the Send or SendInBackground methods on a RaygunClient instance. There are various overloads that you can use to send a list of tags and a dictionary of custom data. These can be whatever you think will help you debug issues, such as the values of local variables.

try
{
  ParseFile(filePath);
}
catch (Exception e)
{
  RaygunClient.Current.SendInBackground(e);
}

User information

You can optionally provide a user identification value that will be sent with each exception log. This will give you an indication of how many users are being affected by a particular bug, which you can then use to decide which bugs are more important to work on next. The user identifier can be whatever you would like. It could be a completely anonymous id, or a database id allowing you to lookup account details that could help debug exceptions. Based on your company/application policies, you could also include additional user information such as a name and email address, which you could use to contact customers to let them know that bugs they have seen have been resolved in a newer version.

RaygunClient.Current.UserInfo = new RaygunIdentifierMessage(id) { FullName = name, Email = email };

Application version

The Xamarin.Mac Raygun provider will automatically send the application version from the NSBundle with each exception report. Exceptions can be filtered by version on your Raygun dashboard. If you want to provide your own version values, you can do so by setting the ApplicationVersion property:

RaygunClient.Current.ApplicationVersion = "2.1.311.4289";

Customize the message before sending

The RaygunClient class has an event called SendingMessage which can be used for two purposes: cancelling a send, or modifying the message before sending. The event handler provides the RaygunMessage object just before it is serialized and sent. You can write logic that looks through the information in the exception message, or other values available in your application to determine whether or not the message should be sent to Raygun. For example, you may not want to send exceptions from certain environments. Additionally, you can make any modifications you want to the message before it is sent. For example, including tags and custom data for unhandled exceptions that are being sent automatically.

Try it out today

Raygun support for Xamarin.Mac applications is available right now from GitHub. If you want awareness of how well your published applications are doing, try integrating Raygun now. If you haven’t signed up yet, try out the free 14 day trial – no credit card required. If you have any questions, we’d love to hear from you in the forum.