-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
82 lines (75 loc) · 3.1 KB
/
App.xaml.cs
File metadata and controls
82 lines (75 loc) · 3.1 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
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
using Microsoft.UI.Xaml;
using System;
using System.Threading.Tasks;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace LegendBar
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
private Window? _window;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
var logPath = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"LegendBar", "crash.log");
try
{
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(logPath)!);
System.IO.File.AppendAllText(logPath,
$"{DateTime.Now} [AppDomain]: {e.ExceptionObject}\n\n");
}
catch { }
};
InitializeComponent();
this.UnhandledException += (s, e) =>
{
e.Handled = true;
System.Diagnostics.Debug.WriteLine($"[App] Unhandled exception: {e.Exception}");
var logPath = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"LegendBar", "crash.log");
try
{
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(logPath)!);
System.IO.File.AppendAllText(logPath,
$"{DateTime.Now}: {e.Exception}\n\n");
}
catch { }
};
TaskScheduler.UnobservedTaskException += (s, e) =>
{
e.SetObserved();
System.Diagnostics.Debug.WriteLine($"[App] Unobserved task exception: {e.Exception}");
var logPath = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"LegendBar", "crash.log");
try
{
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(logPath)!); ;
System.IO.File.AppendAllText(logPath,
$"{DateTime.Now} [Task]: {e.Exception}\n\n");
}
catch { }
};
}
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
_window = new MainWindow();
_window.Activate();
}
}
}