Skip to main content

AppCenter - Crashlog Sink Using AppCenter



Introduction
Appcenter is a Microsoft features product that helps developers/testers/maintainers manage our apps that has been published to the wild. Previously it was known as HockeyApp. In this article, we are going to discuss on how to strategize/handle/manage our crash report mechanism. Since our solution policies may varies between countries, this article will somehow propose a design technique on how to organize our app crash report that is used based on country.

Consideration
This code base is proposed for the intention of specific problem domain that we might encounter throughout our development lifecycle, for production/release we might need to tweak it to meet the company policy, best practice and industry standards. The code snippet is free to use anywhere.

The Assumption
Assuming we are dealing with a lot of phases in our development life cycle, Things like a blue green deployment, Development phase, Testing, and even production-live solutions. It is always nice to segregate our crashlog report in each phase for troubleshooting purpose. If we are deploying our solution worldwide, it is also nice to be able to segregate the crash log based on country, Assuming we have created our android app like below.


We then may design our Apps to use something like below

Create A .Net Standard Library With Nuget Referenced to AppCenter

We going to need Nuget Reference to 3 type of library

using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;

Create All The Environment Variables

using System;
namespace CrashReportLibrary
{
public static class Constant
{
public static class Env
{
public const string Dev = "Dev";
public const string BlueGreen = "BlueGreen";
public const string Pilot = "Pilot";
public const string TestUI = "TestUI";
public const string TestBE = "TestBackEnd";
public const string Live = "Live";
}
public static class Country
{
public const string My = "Malaysia";
public const string Sg = "Singapore";
public const string De = "Germany";
public const string Ne = "Netherlands";
public const string Fr = "France";
}
}
}
Next, we create all the related environment variables that we wish to segregate our crash log to. These variables assuming that we are segregating the sink based on their country and development phases.

Create The Map Logic

namespace CrashReportLibrary
{
public static class CrashKey
{
public static string GetKey(string Env , string Country)
{
// Best practice is to host the key somewhere in a data store . called in a secure manner with both parameters .
if(Env == Constant.Env.BlueGreen)
return "SampleKey-72b3-41be-b01a-2152d70448c7";
if (Env == Constant.Env.Dev)
return "SampleKey-72b3-41be-b01a-2152d70448c7";
if (Env == Constant.Env.TestUI)
return "SampleKey-72b3-41be-b01a-2152d70448c7";
if (Env == Constant.Env.Pilot)
return "SampleKey-72b3-41be-b01a-2152d70448c7";
if (Env == Constant.Env.TestBE)
return "SampleKey-72b3-41be-b01a-2152d70448c7";
if (Env == Constant.Env.Live && Country == Constant.Country.De)
return "SampleKey-72b3-41be-b01a-2152d70448c7";
if (Env == Constant.Env.Live && Country == Constant.Country.My)
return "SampleKey-72b3-41be-b01a-2152d70448c7";
if (Env == Constant.Env.Live && Country == Constant.Country.Ne)
return "SampleKey-72b3-41be-b01a-2152d70448c7";
if (Env == Constant.Env.Live && Country == Constant.Country.Fr)
return "SampleKey-72b3-41be-b01a-2152d70448c7";
if (Env == Constant.Env.Live && Country == Constant.Country.Sg)
return "SampleKey-72b3-41be-b01a-2152d70448c7";
else
return "SampleKey-72b3-41be-b01a-2152d70448c7";
}
}
}
Once we are done with all the environment variables, we now may map the AppCenter keys with our desired environment.

The Reporting Mechanism

using System;
using System.Collections.Generic;
using Microsoft.AppCenter.Crashes;
namespace CrashReportLibrary
{
public static class Report
{
// Overload For Withuot Error Params
public static void SendReport(Exception ex)
{
Crashes.TrackError(ex);
}
// Overload For Some Addition Params
public static void SendReport(Exception ex , Dictionary<string,string> ErrorParams)
{
Crashes.TrackError(ex, ErrorParams);
}
}
}
We Then create a lightweight crash report helper to log our crash exceptions, based on the code snippet above, we decide to add an overloading to the method just in case the client require some data along with the exceptions.

Hooking Up App Variables With A Start Method

using Microsoft.AppCenter;
using Microsoft.AppCenter.Crashes;
using Microsoft.AppCenter.Analytics;
namespace CrashReportLibrary
{
public static class AppCenterStart
{
public static void Start(string ConfigEnv , string Country)
{
AppCenter.Start(CrashKey.GetKey(ConfigEnv, Country),typeof(Crashes));
}
}
}
We then may hook up the CrashReport key with our desired app environment.

Finally, The App Who Consume The Sink
using CrashReportLibrary;
namespace ClientUsage
{
public class Client
{
public void OnStart()
{
AppCenterStart.Start(Config.Env, Config.Country);
}
public void Sample()
{
try
{
int Zeros = 0;
int temp = 1 / Zeros;
}
catch (System.Exception ex)
{
// Call The AppCenter CrashReport Helper Like Below
Report.SendReport(ex);
// Handle Exception
}
}
}
}

Finally , we may then just call the app environment settings to map the crash report sink in our App like above.

Conclusion
From the article, we may conclude that it is important to design our App crash report 'sinks' to help us manage/troubleshoot our application in the wild. We may also assign specific individual based on the Env/Country through app center, this way we have a little management delegation on assigning appropriate users in our AppCenter organizations.

Published on : 4-Jan-2018
Ref no : DDN-WPUB-000214

About Author

My photo
Wan Mohd Adzha MCPD,MCSD,MCSE
I am passionate about technology and of course love Durians. Certified by Microsoft as MCP Since 2011. Blogging from Malaysia

Comments