-
Notifications
You must be signed in to change notification settings - Fork 0
/
StartupHook.cs
36 lines (31 loc) · 1.2 KB
/
StartupHook.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
using MiniDumpStartupHook;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
internal class StartupHook
{
static int _miniDumpExecuted = 0;
public static void Initialize()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine("MiniDump is not supported on non windows platform.");
return;
}
AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
Console.WriteLine("MiniDump startup hook has been initialized.");
}
private static void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
{
var exceptionFullName = e.Exception?.GetType().FullName ?? string.Empty;
var exceptionTypeName = Array.Find(Settings.ExceptionTypes ?? Array.Empty<string>(), item => exceptionFullName.Contains(item));
if (exceptionTypeName != null)
{
if (Interlocked.CompareExchange(ref _miniDumpExecuted, 1, 0) == 0)
{
MiniDump.WriteDump(Process.GetCurrentProcess(), exceptionTypeName);
}
}
}
}