Initial commit: ReminderOrganizer WPF app
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
58
App.xaml.cs
Normal file
58
App.xaml.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ReminderOrganizer.Services;
|
||||
using ReminderOrganizer.ViewModels;
|
||||
|
||||
namespace ReminderOrganizer
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
SetupExceptionHandling();
|
||||
ServiceLocator.Initialize();
|
||||
}
|
||||
|
||||
private void SetupExceptionHandling()
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
|
||||
{
|
||||
LogException((Exception)e.ExceptionObject, "AppDomain.UnhandledException");
|
||||
if (e.IsTerminating)
|
||||
Environment.Exit(1);
|
||||
};
|
||||
|
||||
DispatcherUnhandledException += (s, e) =>
|
||||
{
|
||||
LogException(e.Exception, "DispatcherUnhandledException");
|
||||
e.Handled = true;
|
||||
MessageBox.Show($"An unexpected error occurred:\n{e.Exception.Message}",
|
||||
"Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
};
|
||||
|
||||
TaskScheduler.UnobservedTaskException += (s, e) =>
|
||||
{
|
||||
LogException(e.Exception, "UnobservedTaskException");
|
||||
e.SetObserved();
|
||||
};
|
||||
}
|
||||
|
||||
private static void LogException(Exception ex, string source)
|
||||
{
|
||||
try
|
||||
{
|
||||
var logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "error.log");
|
||||
var logEntry = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{source}]\n{ex}\n\n";
|
||||
File.AppendAllText(logPath, logEntry);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user