From 9d5f73560e6629634965291f7fe2895fa59e34ab Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 14 Aug 2020 19:45:44 +0300 Subject: Added application start logs viewing to FSE & PPC using LogSafe. --- Software/Visual_Studio/Tango.Logging/LogManager.cs | 9 +++++ Software/Visual_Studio/Tango.Logging/LogSafe.cs | 39 ++++++++++++++++++++++ .../Tango.Logging/Tango.Logging.csproj | 3 +- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 Software/Visual_Studio/Tango.Logging/LogSafe.cs (limited to 'Software/Visual_Studio/Tango.Logging') diff --git a/Software/Visual_Studio/Tango.Logging/LogManager.cs b/Software/Visual_Studio/Tango.Logging/LogManager.cs index 55264164a..4148fa342 100644 --- a/Software/Visual_Studio/Tango.Logging/LogManager.cs +++ b/Software/Visual_Studio/Tango.Logging/LogManager.cs @@ -259,5 +259,14 @@ namespace Tango.Logging NewLog?.Invoke(this, log); } } + + /// + /// Creates a new log safe which can be used to keep logs and then be disposed. + /// + /// + public LogSafe CreateLogSafe() + { + return new LogSafe(this); + } } } diff --git a/Software/Visual_Studio/Tango.Logging/LogSafe.cs b/Software/Visual_Studio/Tango.Logging/LogSafe.cs new file mode 100644 index 000000000..2da51e90c --- /dev/null +++ b/Software/Visual_Studio/Tango.Logging/LogSafe.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Logging +{ + public class LogSafe : IDisposable + { + private LogManager _logManager; + private List Logs { get; set; } + + public LogSafe(LogManager logManager) + { + _logManager = logManager; + Logs = new List(); + logManager.NewLog += LogManager_NewLog; + } + + private void LogManager_NewLog(object sender, LogItemBase log) + { + Logs.Add(log); + } + + public List EmptyAndDispose() + { + var list = Logs.ToList(); + Dispose(); + return list; + } + + public void Dispose() + { + _logManager.NewLog -= LogManager_NewLog; + Logs.Clear(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj b/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj index e2e2b1edd..d9a2e1139 100644 --- a/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj +++ b/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj @@ -63,6 +63,7 @@ + @@ -82,7 +83,7 @@ - + \ No newline at end of file -- cgit v1.3.1