Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramApp/App.xaml.cs
2022-10-28 22:45:39 +08:00

43 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)]
namespace AIStudio.Wpf.DiagramApp
{
/// <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);
}
}
}