From ef22b8bc38d2f82b9939c2b6ff6a47d36abbe25b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 14 Aug 2020 20:09:19 +0300 Subject: Improved FSE application termination analysis using settings. (increased crash report history to 1 hour instead of 10 minutes) --- .../FSE/Tango.FSE.Common/FSESettings.cs | 6 +++++ .../Visual_Studio/FSE/Tango.FSE.UI/App.xaml.cs | 30 ++++++++++++++++++++-- .../FSEApplication/DefaultFSEApplicationManager.cs | 2 ++ .../Tango.Logging/GlobalExceptionTrapper.cs | 6 ++--- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/FSESettings.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/FSESettings.cs index 0592aa6cc..352294e0a 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/FSESettings.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/FSESettings.cs @@ -136,6 +136,11 @@ namespace Tango.FSE.Common /// public String LastReportArea { get; set; } + /// + /// Gets or sets a value indicating whether the application has terminated unexpectedly. + /// + public bool TerminatedExpectedly { get; set; } + /// /// Initializes a new instance of the class. /// @@ -152,6 +157,7 @@ namespace Tango.FSE.Common AutoMachineReconnectionTimeoutSeconds = 10; AutoCheckForUpdates = true; EnableAdaptiveScaling = true; + TerminatedExpectedly = true; } } } \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/App.xaml.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/App.xaml.cs index 6bec431fa..8f0b97d2b 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/App.xaml.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/App.xaml.cs @@ -95,14 +95,40 @@ namespace Tango.FSE.UI exceptionTrapper.Initialize(this); exceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed; - GetLastApplicationCrashFromWindows(); + if (!Debugger.IsAttached) + { + ProcessLastApplicationTermination(); + } } #region Global Exception Trapping + private void ProcessLastApplicationTermination() + { + try + { + LogManager.Log("Analyzing previous application termination state..."); + + var settings = SettingsManager.Default.GetOrCreate(); + + if (!settings.TerminatedExpectedly) + { + GetLastApplicationCrashFromWindows(); + } + + settings.TerminatedExpectedly = false; + settings.Save(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error occurred while processing application last termination state."); + } + } + private async void GetLastApplicationCrashFromWindows() { - var logItem = await exceptionTrapper.GetLastApplicationCrashEventLog(); + //Try find event log crash reports from the last 60 minutes... + var logItem = await exceptionTrapper.GetLastApplicationCrashEventLog(60); if (logItem != null) { IsStartedAfterCrash = true; diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/FSEApplication/DefaultFSEApplicationManager.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/FSEApplication/DefaultFSEApplicationManager.cs index 2346afdfb..48087bff9 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/FSEApplication/DefaultFSEApplicationManager.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/FSEApplication/DefaultFSEApplicationManager.cs @@ -391,6 +391,8 @@ namespace Tango.FSE.UI.FSEApplication try { + var settings = SettingsManager.Default.GetOrCreate(); + settings.TerminatedExpectedly = true; SettingsManager.Default.Save(); } catch { } diff --git a/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs b/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs index 722bceb56..8bc3729f2 100644 --- a/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs +++ b/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs @@ -102,7 +102,7 @@ namespace Tango.Logging return e.TryRecover; } - public Task GetLastApplicationCrashEventLog() + public Task GetLastApplicationCrashEventLog(int maxMinutes = 10) { return Task.Factory.StartNew(() => { @@ -111,7 +111,7 @@ namespace Tango.Logging try { var applicationEvents = new EventLog("Application"); - var events = applicationEvents.Entries.Cast().Where(x => x.EntryType == EventLogEntryType.Error && x.Source == ".NET Runtime" && x.TimeWritten > DateTime.Now.AddMinutes(-10)).OrderByDescending(x => x.TimeWritten).ToList(); + var events = applicationEvents.Entries.Cast().Where(x => x.EntryType == EventLogEntryType.Error && x.Source == ".NET Runtime" && x.TimeWritten > DateTime.Now.AddMinutes(-maxMinutes)).OrderByDescending(x => x.TimeWritten).ToList(); Regex reg = new Regex("Application: (.+)"); @@ -131,7 +131,7 @@ namespace Tango.Logging logItem.Message += "---------------------------------------------------------------------------\n\n"; logItem.Message += ev.Message; logItem.TimeStamp = DateTime.Now; - logItem.Category = LogCategory.Error; + logItem.Category = LogCategory.Critical; break; } } -- cgit v1.3.1