|
|
|
@ -4,6 +4,7 @@ using System.IO; |
|
|
|
|
using System.Windows; |
|
|
|
|
using System.Windows.Media; |
|
|
|
|
using System.Windows.Threading; |
|
|
|
|
using BrilliantSightClient.Model.Exceptions; |
|
|
|
|
using log4net; |
|
|
|
|
using log4net.Config; |
|
|
|
|
using BrilliantSightClient.Model.Helper; |
|
|
|
@ -17,13 +18,29 @@ namespace BrilliantSightClient; |
|
|
|
|
public partial class App : Application |
|
|
|
|
{ |
|
|
|
|
private static readonly ILog Logger = LogManager.GetLogger(typeof(App)); |
|
|
|
|
|
|
|
|
|
private static Mutex? _mutex = null; |
|
|
|
|
|
|
|
|
|
protected override void OnStartup(StartupEventArgs e) |
|
|
|
|
{ |
|
|
|
|
const string appName = "BrilliantSight"; |
|
|
|
|
bool createdNew; |
|
|
|
|
_mutex = new Mutex(true, $"Global\\{{{appName}}}", out createdNew); |
|
|
|
|
if (!createdNew) |
|
|
|
|
{ |
|
|
|
|
MessageBox.Show("An instance of this application is already running.", |
|
|
|
|
"BrilliantSight Is Running", |
|
|
|
|
MessageBoxButton.OK, |
|
|
|
|
MessageBoxImage.Warning); |
|
|
|
|
Shutdown(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
base.OnStartup(e); |
|
|
|
|
//加载日志配置文件 |
|
|
|
|
XmlConfigurator.Configure(new FileInfo("log4net.config")); |
|
|
|
|
Logger.Info("==== ==== ==== ==== ==== ==== ==== ===="); |
|
|
|
|
Logger.Info("App Client Start: App Initialize"); |
|
|
|
|
|
|
|
|
|
Logger.Info("Loaded Logs Config: log4net.config"); |
|
|
|
|
//运行是否需要归档 |
|
|
|
|
Log4NetHelper.ArchiveOldLogs(); |
|
|
|
@ -56,10 +73,17 @@ public partial class App : Application |
|
|
|
|
Logger.Info("App Client Start: App Initialize Succeed !!!"); |
|
|
|
|
DispatcherUnhandledException += (s, ex) => |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
MessageBox.Show($"致命错误: {ex.Exception.Message}"); |
|
|
|
|
Logger.Error($"发生致命错误!!!{ex.Exception.Message}{ex.Exception.StackTrace}"); |
|
|
|
|
ex.Handled = true; |
|
|
|
|
}; |
|
|
|
|
Logger.Info("==== ==== ==== ==== ==== ==== ==== ===="); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected override void OnExit(ExitEventArgs e) |
|
|
|
|
{ |
|
|
|
|
_mutex?.ReleaseMutex(); |
|
|
|
|
base.OnExit(e); |
|
|
|
|
} |
|
|
|
|
} |