-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCrashLogger.cs
93 lines (82 loc) · 3.23 KB
/
CrashLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
namespace ESuite
{
public static class CrashLogger
{
#if ANDROID
public static Android.Content.Context Context;
#endif
public static void GlobalUnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
Exception ex = default(Exception);
ex = (Exception)e.ExceptionObject;
DumpExceptionDetails (ex);
}
private static Version currentVersion
{
get
{
return
#if ANDROID
new Version(Context.PackageManager.GetPackageInfo (Context.PackageName, 0).VersionName);
#elif IOS
new Version(Foundation.NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString());
#else
System.Reflection.Assembly.GetEntryAssembly().GetName().Version;
#endif
}
}
private static String OSVersion
{
get
{
return
#if ANDROID
"Android";
#elif IOS
"iOS";
#elif WINDOWS
"Windows " + System.Environment.OSVersion.VersionString;
#elif LINUX
"Linux";
#else
"UNKNOWN";
#endif
}
}
public static void DumpExceptionDetails(Exception ex)
{
DateTime now = DateTime.Now;
string filename = "LabNation_CrashReport_" + now.Year.ToString("0000") + now.Month.ToString("00") + now.Day.ToString("00") + now.Hour.ToString("00") + now.Minute.ToString("00") + now.Second.ToString("00") + now.Millisecond.ToString("000") + ".txt";
string fullPath = System.IO.Path.Combine(LabNation.Common.Utils.StoragePath, filename);
try
{
System.IO.StreamWriter writer = new System.IO.StreamWriter(new System.IO.FileStream(fullPath, System.IO.FileMode.Append));
writer.WriteLine("-----------------------------------------------------------------------------------------");
writer.WriteLine("------------------------------ CRASH REPORT ------------------------------");
writer.WriteLine("Timestamp: " + now.ToLocalTime());
while (ex != null)
{
try
{
writer.WriteLine("SmartScopeApp version: " + currentVersion.ToString());
writer.WriteLine("OS: " + OSVersion);
writer.WriteLine("Error message: " + ex.Message);
writer.WriteLine("Source: " + ex.Source);
writer.WriteLine("TargetSite: " + ex.TargetSite.Name);
writer.WriteLine("StackTrace: " + ex.StackTrace);
writer.WriteLine("-----------------------------------------------------------------------------------------");
}
catch
{ }
ex = ex.InnerException;
}
writer.Flush();
writer.Close();
}
catch { }
LabNation.Common.Logger.Error(": !!! CRASH !!! Details saved to " + fullPath + ", please send that file to [email protected] so we can fix it");
LabNation.Common.FileLogger.StopAll();
}
}
}