-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
46 lines (42 loc) · 1.46 KB
/
Copy pathApp.xaml.cs
File metadata and controls
46 lines (42 loc) · 1.46 KB
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
using System.Windows;
namespace SonicBoard
{
/// <summary>
/// Application entry point.
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
AppDomain.CurrentDomain.UnhandledException += (s, args) =>
{
LogException(args.ExceptionObject as Exception);
};
DispatcherUnhandledException += (s, args) =>
{
LogException(args.Exception);
args.Handled = true;
};
try
{
base.OnStartup(e);
}
catch (Exception ex)
{
LogException(ex);
throw;
}
}
private void LogException(Exception? ex)
{
if (ex == null) return;
try
{
string logPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "crash.txt");
System.IO.File.WriteAllText(logPath, $"Time: {DateTime.Now}\nException: {ex.GetType().Name}\nMessage: {ex.Message}\nStackTrace:\n{ex.StackTrace}\n\nInnerException:\n{ex.InnerException?.Message}\n{ex.InnerException?.StackTrace}");
MessageBox.Show($"Application crashed on startup. Error logged to crash.txt:\n\n{ex.Message}", "SonicBoard Crash Detector", MessageBoxButton.OK, MessageBoxImage.Error);
}
catch { }
}
}
}