diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-12 23:45:47 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-12 23:45:47 +0300 |
| commit | 30f5a25d16b65c267c2658861c50b50c39877bc4 (patch) | |
| tree | 19e1beed32b3d612c26f025724c5adf72039f9a0 /Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs | |
| parent | 9149538fdf00ab97647b36fed3282f2037da4b2d (diff) | |
| download | Tango-30f5a25d16b65c267c2658861c50b50c39877bc4.tar.gz Tango-30f5a25d16b65c267c2658861c50b50c39877bc4.zip | |
Implemented global exception trapper GetLastApplicationCrashFromWindows for PPC/FSE/MS.
Diffstat (limited to 'Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs b/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs index 7580eea31..f301e0086 100644 --- a/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs +++ b/Software/Visual_Studio/Tango.Logging/GlobalExceptionTrapper.cs @@ -1,8 +1,12 @@ 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; @@ -97,5 +101,46 @@ namespace Tango.Logging return e.TryRecover; } + + public Task<MessageLogItem> GetLastApplicationCrashEventLog() + { + return Task.Factory.StartNew<MessageLogItem>(() => + { + 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(-10)).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 started after a crash!\n"; + logItem.Message += "This log was retrieved from the windows event logs.\n"; + logItem.Message += "---------------------------------------------------------\n\n"; + logItem.Message += ev.Message; + logItem.TimeStamp = DateTime.Now; + logItem.Category = LogCategory.Error; + break; + } + } + } + } + catch { } + + return logItem; + }); + } } } |
