protected override void OnStartup(StartupEventArgs e) { LogToFile.LogDebug("App started"); Settings.Load(); base.OnStartup(e); AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException; }
protected override void OnExit(ExitEventArgs e) { Settings.Save(); LogToFile.LogDebug("App exiting"); LogToFile.Close(); base.OnExit(e); }
private void Log(LogMode mode, String logentry) { LogToFile.Log(mode, logentry); System.Windows.Application.Current.Dispatcher.Invoke(() => { if (LogEntries.Count >= 100) { LogEntries.RemoveAt(LogEntries.Count - 1); } LogEntries.Insert(0, new LogEntryDO(mode, logentry)); }); }
private void SaveImpl() { var spath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, SettingsFile); try { var data = JsonConvert.SerializeObject(this, _jsonsettings); if (File.Exists(spath)) { File.Delete(spath); } File.WriteAllText(spath, data); } catch (Exception ex) { LogToFile.LogError("Error saving SettingsFile[{0}]:{1}", spath, ex); } }
private void LoadImpl() { var spath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, SettingsFile); try { Console.WriteLine("Opening SettingsFile[" + spath + "]"); if (File.Exists(spath)) { var data = File.ReadAllText(spath); var obj = JsonConvert.DeserializeObject(data, _jsonsettings); CopyOntoSelf(obj as Settings); } else { LogToFile.LogWarn("SettingsFile [{0}] does not exist!", spath); } } catch (Exception ex) { LogToFile.LogError("Error loading SettingsFile[{0}]: {1}", spath, ex); } }
void AppDomain_CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { LogToFile.LogError("CRASH:", e.ExceptionObject as Exception); LogToFile.Close(); }
void _loadThread_ThreadExceptionOccurred(object sender, ThreadExceptionEventArgs e) { Log(LogMode.Error, "Update-Thread-Crash! " + e.Exception); LogToFile.LogError("Update-Thread-Exception:{0}", e.Exception); IsUpdating = false; }