×


ErrLog.IO and Xamarin.Forms
Xamarin.Forms is a .Net framework used for building cross-platform applications for iOS, Android and Windows (UWP). ErrLog is fully supported in Xamarin.Forms, and is a great way to take more control over your exception loggins when developing cross-platform applications.
These examples assume you have a typical Shared Project containing your shared class library and platform-specific sub-projects.
Installing the Nuget Package into your Xamarin.Forms Project
Use Nuget or an equivalent package manager to download and install ErrLog.IO. Remember to install the package for each platform-specific project - iOS, Android and UWP.
ErrLog Logo Instantiating ErrLog.IO to Log Errors & Exceptions
Typically you can activate ErrLog.IO either on a page-by-page basis, or within your startup class.
public partial class MainPage : ContentPage
{ 
	public MainPage ()
	{
		ErrLog.settings.apikey = "[Your-api-key]";
	}
}
Global App Startup Class
You can also install ErrLog.IO in your app.xaml.cs class.
public partial class App : Application
{
	public App()
	{
		InitializeComponent();

		ErrLog.settings.apikey = "[Your-api-key]";
	}
}
 Capturing Errors and Exceptions
There are a number of event handlers available in Xamarin.Forms for capturing exceptions. Below are examples of how to add a custom event handler to send Exceptions directly to ErrLog.IO
Shared Class Library
static void logError(object sender, UnhandledExceptionEventArgs args)
{
	Exception ex = (Exception)args.ExceptionObject;
	ErrLog.logger.log(ex);
}
Android
AppDomain.CurrentDomain.UnhandledException += logError;
TaskScheduler.UnobservedTaskException += logError;
AndroidEnvironment.UnhandledExceptionRaiser += logError;
iOS
AppDomain.CurrentDomain.UnhandledException += async (sender, e) => logError
TaskScheduler.UnobservedTaskException += async (sender, e) => logError
Windows UWP
UnhandledException += logError;

 

Discuss this article