Files
hk4e-gm-clone/csharp/App.xaml.cs
T

30 lines
830 B
C#

using System.Windows;
namespace Hk4eGm;
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
AppDomain.CurrentDomain.UnhandledException += (_, args) =>
Dump(args.ExceptionObject as Exception);
DispatcherUnhandledException += (_, args) =>
{
Dump(args.Exception);
MessageBox.Show(args.Exception.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
args.Handled = true;
};
}
private static void Dump(Exception? ex)
{
try
{
var path = System.IO.Path.Combine(AppContext.BaseDirectory, "crash.log");
System.IO.File.AppendAllText(path, $"[{DateTime.Now:HH:mm:ss}] {ex}\n\n");
}
catch { }
}
}