This repository was archived by the owner on Jul 30, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
93 lines (81 loc) · 3.05 KB
/
Copy pathProgram.cs
File metadata and controls
93 lines (81 loc) · 3.05 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
83
84
85
86
87
88
89
90
91
92
93
using Avalonia;
using System;
namespace TagForge;
sealed class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
{
// Set up global exception handlers
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
{
if (error.ExceptionObject is Exception ex)
{
LogCrash(ex, "AppDomain.UnhandledException");
}
};
System.Threading.Tasks.TaskScheduler.UnobservedTaskException += (sender, error) =>
{
LogCrash(error.Exception, "TaskScheduler.UnobservedTaskException");
error.SetObserved();
};
try
{
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
catch (Exception ex)
{
LogCrash(ex, "Main Loop Exception");
// You might want to rethrow if you want the OS to still see it as a crash,
// but usually logging and exiting is what's desired for a custom crash reporter.
}
}
private static void LogCrash(Exception ex, string source)
{
try
{
string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string appDirectory = System.IO.Path.Combine(userProfile, ".tagforge");
if (!System.IO.Directory.Exists(appDirectory))
{
System.IO.Directory.CreateDirectory(appDirectory);
}
string timestamp = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
string fileName = System.IO.Path.Combine(appDirectory, $"crash_log_{timestamp}.txt");
string crashReport = $"""
TagForge Crash Report
=====================
Timestamp: {DateTime.Now}
Source: {source}
Exception Message:
{ex.Message}
Stack Trace:
{ex.StackTrace}
Inner Exception:
{ex.InnerException}
""";
System.IO.File.WriteAllText(fileName, crashReport);
// Also output to console for development/CLI users
Console.Error.WriteLine(crashReport);
}
catch (Exception fallbackEx)
{
// If primary logging fails, try to output to console as last resort
try
{
Console.Error.WriteLine($"CRITICAL ERROR: Could not write crash log. Original error: {ex.Message}\nLogging error: {fallbackEx.Message}");
}
catch { /* Total failure */ }
}
}
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}