A complete, ligthweight and self-contained .NET Standard 2.0 offline exception logging library, powered by Realm


Keywords
csharp, netstandard, realm, exception, report, debug, coding, test, log, android-library, asp-net, aspnetcore, dll, ios-lib, netstandard20, uwp, uwp-applications, uwp-apps, windows-10, windows-uwp, xamarin, xamarin-android, xamarin-ios, xamarin-library, xamarin-studio
License
GPL-3.0
Install
Install-Package BigWatson -Version 1.5.3

Documentation

NuGet NuGet AppVeyor AppVeyor tests Twitter Follow

A .NET Standard 2.0 library to easily log and review offline exception reports and messages for an app.

Table of Contents

Installing from NuGet

To install BigWatson, run the following command in the Package Manager Console

Install-Package BigWatson

More details available here.

Quick start

The library exposes various APIs to easily log exceptions and then manage the logs database.

Setup

The only thing that's needed to get started with the library is to add an event handler to log the exceptions:

this.UnhandledException += (s, e) => BigWatson.Instance.Log(e.Exception);

And that's it! The library will now automatically log every exception thrown by the app and build a complete database with all the crash reports and their useful info, including the app version and the app memory usage.

NOTE: on some frameworks, the APIs used by the library to retrieve the amount of used memory are not supported and will cause a crash at runtime. In order to solve this, the BigWatson class exposes a Func<long> MemoryParser property that can be used to assign an arbitrary method, using the appropriate APIs for the target platform. Moreover, on some platforms it might be necessary to manually specify how to retrieve the correct app version as well. As an example, on UWP:

BigWatson.MemoryParser = () => (long)Windows.System.MemoryManager.AppMemoryUsage;
BigWatson.VersionParser = () =>
{
    PackageVersion version = Package.Current.Id.Version;
    return new Version(version.Major, version.Minor, version.Build, version.Revision);
}; 

Browse reports

It is possible to load the complete list of previous exception reports, sorted by app versions, using:

var reports = await BigWatson.Instance.LoadExceptionsAsync();

To load only the reports of a specific type, just use the following overload:

var reports = await BigWatson.Instance.LoadExceptionsAsync<InvalidOperationException>();

It is also possible to trim the local exceptions database by deleting old reports that are no longer needed:

await BigWatson.Instance.TrimAsync(TimeSpan.FromDays(30));

Event logs

Using BigWatson it is also possible to save event reports, which can be useful for analytics or debugging purposes:

BigWatson.Instance.Log(EventPriority.Info, "The user used the app 2 times today");

External databases

If you want to share your crash reports database with someone else, or if you'd like your customers to be able to send their reports database to you, the library has some APIs to quickly share a database and load an external database file:

// Client-side
await BigWatson.Instance.ExportAsync(pathToExportDatabase);

// Developer side
IReadOnlyLogger logger = BigWatson.Load(pathToDatabase);
var reports = await logger.LoadExceptionsAsync();

Dependencies

The libraries use the following libraries and NuGet packages:

Credits

BigWatson UWP is an extension of the LittleWatson class by Alex Hardwicke. In addition to that, this updated library also includes an internal Realm database to store and retrieve previous logs, and additional APIs. The icon base image was made by Aldric Rodríguez from thenounproject.com.