Introducing support for Xamarin

You already know elmah.io as a great system for logging from .NET web backends and JavaScript. Today, we are ready to show a new type of integration we have been working on: Xamarin error logging support. That's right, logging errors from mobile applications developed in Xamarin and Xamarin.Forms are now as easy as you know it from the web world.

Integrating is already thoroughly documented on the documentation site: Logging to elmah.io from Xamarin. But here's a quick getting started guide as well as some screenshots from within the elmah.io UI to illustrate how the integration is working.

Logging to elmah.io from Xamarin starts by installing the Elmah.Io.Xamarin NuGet package and adding a bit of code. In this example, we will include error logging to an Android application running on Xamarin.Forms:

ElmahIoXamarin.Init(new ElmahIoXamarinOptions
{
    ApiKey = "API_KEY",
    LogId = new Guid("LOG_ID"),
});
AndroidEnvironment.UnhandledExceptionRaiser += (sender, e) =>
{
    e.Exception.Log();
    e.Handled = true;
};
TaskScheduler.UnobservedTaskException += (sender, e) =>
{
    e.Exception.Log();
    e.SetObserved();
};

By calling the Init method on ElmahIoXamarin the elmah.io client is initialized and set up for logging to the specified log ID using the user's API key. Logging all uncaught exceptions is done by subscribing to the two error events provided by Xamarin. Exceptions can also be logged manually using the Log extension method provided by the Elmah.Io.Xamarin package:

try
{
    // Code that may break
}
catch (Exception e)
{
    e.Log();
}

When looking inside the elmah.io UI, errors logged from Xamarin apps are easily identified using the device graphic that you already know from log messages stored by web servers and browsers:

Metadata about the device causing the error like the screen resolution, orientation, and operating system is automatically extracted by the Xamarin integration and stored on elmah.io. Additional information can be found on the Data tab in Extended message details view.

Showing only mobile log messages can be done using the new Is Mobile filter in the UI:

The integration with Xamarin is currently in prerelease and we are looking for people who want to try out the new package. Make sure to reach out if you are a Xamarin developer and want to start experiencing magic with Xamarin and elmah.io.