Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramApp/App.xaml.cs

43 lines
1.6 KiB
C#
Raw Normal View History

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);
}
}
}