2021-07-23 09:42:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
|
|
//注意下面的语句一定要加上,指定log4net使用.config文件来读取配置信息
|
|
|
|
|
|
//如果是WinForm(假定程序为MyDemo.exe,则需要一个MyDemo.exe.config文件)
|
|
|
|
|
|
//如果是WebForm,则从web.config中读取相关信息
|
|
|
|
|
|
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
|
2022-10-28 22:45:39 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramApp
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Interaction logic for App.xaml
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class App : Application
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public App()
|
|
|
|
|
|
{
|
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
|
|
|
|
|
Application.Current.DispatcherUnhandledException += Application_DispatcherUnhandledException;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
|
|
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//记录严重错误
|
|
|
|
|
|
log.Fatal(e.Exception);
|
|
|
|
|
|
e.Handled = true;//使用这一行代码告诉运行时,该异常被处理了,不再作为UnhandledException抛出了。
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//记录严重错误
|
|
|
|
|
|
log.Fatal(e.ExceptionObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|