aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
committerMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
commit00a491d93733d4625ad329b2ba8237f445364b3f (patch)
tree4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d9.tar.gz
Tango-00a491d9.zip
merge
Diffstat (limited to 'Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs')
-rw-r--r--Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs65
1 files changed, 7 insertions, 58 deletions
diff --git a/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs b/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs
index 3409ffdc4..5ee714cb6 100644
--- a/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs
+++ b/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
using System.Linq;
-using System.Reflection;
-using System.Runtime.ExceptionServices;
using System.Text;
-using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
@@ -21,7 +16,6 @@ namespace Tango.Logging
public class WpfGlobalExceptionTrapper : IGlobalExceptionTrapper
{
private DateTime _lastGlobalExceptionTime = DateTime.Now.AddMinutes(-1);
- private Application _app;
/// <summary>
/// Occurs when the global exception trapper has detected an unhandled exception.
@@ -34,7 +28,6 @@ namespace Tango.Logging
/// <param name="app">The application.</param>
public void Initialize(Application app)
{
- _app = app;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
app.Dispatcher.UnhandledException += Dispatcher_UnhandledException;
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
@@ -42,17 +35,6 @@ namespace Tango.Logging
}
/// <summary>
- /// Use only when need to simulate application crash!
- /// </summary>
- public void Disable()
- {
- AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
- _app.Dispatcher.UnhandledException -= Dispatcher_UnhandledException;
- Application.Current.DispatcherUnhandledException -= Current_DispatcherUnhandledException;
- TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException;
- }
-
- /// <summary>
/// Handles the UnobservedTaskException event of the TaskScheduler control.
/// </summary>
/// <param name="sender">The source of the event.</param>
@@ -101,58 +83,25 @@ namespace Tango.Logging
{
if (DateTime.Now < _lastGlobalExceptionTime.AddSeconds(1))
{
+ LogManager.Default.Log(exception, LogCategory.Critical);
_lastGlobalExceptionTime = DateTime.Now;
return true;
}
_lastGlobalExceptionTime = DateTime.Now;
+ LogManager.Default.Log("Application Crashed", LogCategory.Critical);
+ LogManager.Default.Log(exception, LogCategory.Critical);
ApplicationCrashedEventArgs e = new ApplicationCrashedEventArgs(exception);
ApplicationCrashed?.Invoke(this, e);
- return e.TryRecover;
- }
-
- public Task<MessageLogItem> GetLastApplicationCrashEventLog(int maxMinutes = 10)
- {
- return Task.Factory.StartNew<MessageLogItem>(() =>
+ if (e.TryRecover)
{
- MessageLogItem logItem = null;
-
- try
- {
- var applicationEvents = new EventLog("Application");
- var events = applicationEvents.Entries.Cast<EventLogEntry>().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: (.+)");
-
- foreach (var ev in events)
- {
- Match match = reg.Match(ev.Message);
- if (match.Groups.Count > 1)
- {
- String exeName = match.Groups[1].Value;
- String assemblyName = Path.GetFileNameWithoutExtension(exeName);
-
- if (assemblyName == Assembly.GetEntryAssembly().GetName().Name)
- {
- logItem = new MessageLogItem();
- logItem.Message = "Application terminated unexpectedly in the previous run!\n";
- logItem.Message += "This crash report was retrieved from the windows event logs.\n";
- logItem.Message += "---------------------------------------------------------------------------\n\n";
- logItem.Message += ev.Message;
- logItem.TimeStamp = DateTime.Now;
- logItem.Category = LogCategory.Critical;
- break;
- }
- }
- }
- }
- catch { }
+ LogManager.Default.Log("Trying application recovery. Ignoring exception...");
+ }
- return logItem;
- });
+ return e.TryRecover;
}
}
}