An open API service indexing awesome lists of open source software.

https://github.com/sergio0694/traceyourstacklibrary

A multi-platform library for the Tys APIs
https://github.com/sergio0694/traceyourstacklibrary

Last synced: 7 months ago
JSON representation

A multi-platform library for the Tys APIs

Awesome Lists containing this project

README

          

# TraceYourStackLibrary

A multi-platform library for the TraceYourStack APIs.

This library is written in C# and can be used with Xamarin (iOS, Android, etc..), WPF programs, WinRT and UWP applications and more.

With this library it's easy to use the TraceYourStack web service without having to manually prepare the JSON content to send and managing the HTTP calls.
It also implementes a local database to queue the generated exceptions report in case there isn't an available internet connection to upload them immediately.

## Usage

The library exposes various APIs to easily initialize and use the service. Before using it, it's necessary to login to the TraceYourStack service, to create an application and get its authorization token.

**NOTE:** it's also necessary to include the following NuGet packages in the project in order to use the library:

* SQLite.Net-PCL
* SQLite.Net-Core-PCL
* PCLStorage

### Initialization

The first step is to initialize the library in the app constructor:

```C#
// Initialize the SQLite platform
ISQLitePlatform platform = new SQLitePlatformWinRT();

// Chose a method to obtain a unique name for the current device
EasClientDeviceInformation info = new EasClientDeviceInformation();
String device = $"{info.SystemManufacturer} {info.SystemProductName}";

// Initialize the library with the following parameters and the authorization token
TysAPIs.InitializeLibrary(platform, new WinRTSettings(), device, TraceYourStackAuthorizationToken);
```

### Save the exceptions

Add this code to store every new Exception that is generated:

```C#
this.UnhandledException += (s, e) =>
{
PackageVersion pVersion = Package.Current.Id.Version;
Version version = new Version(pVersion.Major, pVersion.Minor, pVersion.Build, pVersion.Revision);
TysAPIs.LogException(e.Exception, version);
};
```

### Upload the reports

Use this call during the app startup to upload the existing reports

```C#
CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
ExceptionReportFlushResult result = await TysAPIs.FlushExceptionsQueueAsync(cts.Token);
```

### Load the local reports

It is also possible to get a list of the reports generated by the device in use, to display them into the app.

```C#
IEnumerable> reports = await TysAPIs.LoadExceptionReportsAsync();
```