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.
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.
Install-Package errlog.io
dotnet add package errlog.io
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]";
}
}
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]";
}
}
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
static void logError(object sender, UnhandledExceptionEventArgs args)
{
Exception ex = (Exception)args.ExceptionObject;
ErrLog.logger.log(ex);
}
AppDomain.CurrentDomain.UnhandledException += logError;
TaskScheduler.UnobservedTaskException += logError;
AndroidEnvironment.UnhandledExceptionRaiser += logError;
AppDomain.CurrentDomain.UnhandledException += async (sender, e) => logError
TaskScheduler.UnobservedTaskException += async (sender, e) => logError
UnhandledException += logError;
Discuss this article