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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AppCenter; | |
using Microsoft.AppCenter.Analytics; | |
using Microsoft.AppCenter.Crashes; |
Create All The Environment Variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} | |
} |
Create The Map Logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} | |
} |
The Reporting Mechanism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Hooking Up App Variables With A Start Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} | |
} |
Finally, The App Who Consume The Sink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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

Comments
Post a Comment