ForeverZero_DataSync/App.xaml.cs
using System.Windows;
using System.Windows.Threading;
using NLog;

namespace DataSynchronizor
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            DispatcherUnhandledException += App_DispatcherUnhandledException;
        }

        public static void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            Logger.Error($"系统异常: {e}", e);
            // Process unhandled exception
            MessageBox.Show($"{e.Exception}", "系统异常", MessageBoxButton.OK, MessageBoxImage.Error);
            // Prevent default unhandled exception processing
            e.Handled = false;
        }
    }
}