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
- Host: GitHub
- URL: https://github.com/sergio0694/traceyourstacklibrary
- Owner: Sergio0694
- Created: 2016-10-06T23:40:53.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-05T12:55:44.000Z (almost 9 years ago)
- Last Synced: 2025-01-26T06:41:48.921Z (9 months ago)
- Language: C#
- Size: 43 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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();
```