diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-14 19:45:44 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-14 19:45:44 +0300 |
| commit | 9d5f73560e6629634965291f7fe2895fa59e34ab (patch) | |
| tree | 131d6cdc6b17aab85a16ff30da936ba5d3953b21 /Software/Visual_Studio | |
| parent | dc519b8dbd294a2a956f051bca63a30eb9c07986 (diff) | |
| download | Tango-9d5f73560e6629634965291f7fe2895fa59e34ab.tar.gz Tango-9d5f73560e6629634965291f7fe2895fa59e34ab.zip | |
Added application start logs viewing to FSE & PPC using LogSafe.
Diffstat (limited to 'Software/Visual_Studio')
11 files changed, 126 insertions, 6 deletions
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Helpers/LogsHelper.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Helpers/LogsHelper.cs new file mode 100644 index 000000000..eac030fb8 --- /dev/null +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Helpers/LogsHelper.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Logging; + +namespace Tango.FSE.Common.Helpers +{ + public static class LogsHelper + { + private static LogSafe _logSafe; + + public static void SetLogSafe(LogSafe logSafe) + { + _logSafe = logSafe; + } + + public static LogSafe GetLogSafe() + { + return _logSafe; + } + } +} diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj b/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj index a4668edb4..6c7ffb7ed 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj @@ -192,6 +192,7 @@ <Compile Include="Graphs\GraphHelper.cs" /> <Compile Include="Helpers\DesignModeHelper.cs" /> <Compile Include="Helpers\EncryptionHelper.cs" /> + <Compile Include="Helpers\LogsHelper.cs" /> <Compile Include="Helpers\ResourceHelper.cs" /> <Compile Include="INotifyApplicationStarted.cs" /> <Compile Include="INotifyApplicationReady.cs" /> 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 e0c6de0e1..6bec431fa 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/App.xaml.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/App.xaml.cs @@ -84,8 +84,8 @@ namespace Tango.FSE.UI operatorLogger.EnableMaxFileSizeLimit = true; } - LogManager.Log("Application Started..."); - LogManager.Log($"Application Version: '{AssemblyHelper.GetCurrentAssemblyVersion()}'."); + LogsHelper.SetLogSafe(LogManager.CreateLogSafe()); + LogManager.Log($"Application Started... Version: '{AssemblyHelper.GetCurrentAssemblyVersion()}'."); WebRequest.DefaultWebProxy = null; diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/LogViewerPaneVM.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/LogViewerPaneVM.cs index 050b17dcc..2add8f473 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/LogViewerPaneVM.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/LogViewerPaneVM.cs @@ -12,6 +12,7 @@ using Tango.Core.DI; using Tango.FSE.Common; using Tango.FSE.Common.Connection; using Tango.FSE.Common.Dialogs; +using Tango.FSE.Common.Helpers; using Tango.Integration.Logging; using Tango.Logging; using Tango.SharedUI.Components; @@ -232,6 +233,13 @@ namespace Tango.FSE.UI.Panes TangoIOC.Default.Inject(this); + var appStartLogs = LogsHelper.GetLogSafe().EmptyAndDispose(); + + foreach (var log in appStartLogs) + { + FSELogs.Insert(0, log); + } + LoggingProvider.FSELogAvailable += LoggingProvider_FSELogAvailable; LoggingProvider.ApplicationLogAvailable += LoggingProvider_ApplicationLogAvailable; LoggingProvider.FirmwareLogAvailable += LoggingProvider_FirmwareLogAvailable; diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/LoggingViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/LoggingViewVM.cs index a0110b18a..2aee7f561 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/LoggingViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/LoggingViewVM.cs @@ -12,6 +12,7 @@ using Tango.Integration.Logging; using Tango.Integration.Operation; using Tango.Logging; using Tango.PPC.Common; +using Tango.PPC.Common.Helpers; using Tango.PPC.Technician.Dialogs; namespace Tango.PPC.Technician.ViewModels @@ -86,6 +87,13 @@ namespace Tango.PPC.Technician.ViewModels paused_logs = new List<LogItemBase>(); paused_embedded_logs = new List<LogItemBase>(); + var appStartLogs = LogsHelper.GetLogSafe().EmptyAndDispose(); + + foreach (var log in appStartLogs) + { + ApplicationLogs.Insert(0, log); + } + LogManager.NewLog += LogManager_NewLog; MachineOperator.EmbeddedLogManager.NewLog += EmbeddedLogManager_NewLog; ClearCommand = new RelayCommand(ClearLogs); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/LogsHelper.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/LogsHelper.cs new file mode 100644 index 000000000..b7ab2d5b8 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/LogsHelper.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Logging; + +namespace Tango.PPC.Common.Helpers +{ + public static class LogsHelper + { + private static LogSafe _logSafe; + + public static void SetLogSafe(LogSafe logSafe) + { + _logSafe = logSafe; + } + + public static LogSafe GetLogSafe() + { + return _logSafe; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 32f3b865b..b15ca60bd 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -160,6 +160,7 @@ <Compile Include="FileSystem\FileSystemOperationMode.cs" /> <Compile Include="FileSystem\IFileSystemService.cs" /> <Compile Include="Helpers\KeyboardHelper.cs" /> + <Compile Include="Helpers\LogsHelper.cs" /> <Compile Include="HotSpot\DefaultHotSpotProvider.cs" /> <Compile Include="HotSpot\IHotSpotProvider.cs" /> <Compile Include="IPPCView.cs" /> @@ -476,7 +477,7 @@ </Target> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs index 7d8304209..78536803c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs @@ -17,6 +17,7 @@ using Tango.Integration.Operation; using Tango.Logging; using Tango.PPC.Common; using Tango.PPC.Common.EventLogging; +using Tango.PPC.Common.Helpers; using Tango.PPC.Common.Notifications; using Tango.PPC.Common.WatchDog; using Tango.Settings; @@ -55,7 +56,10 @@ namespace Tango.PPC.UI //LogManager.RegisterLogger(new ConsoleLogger("Tango PPC Debug")); LogManager.RegisterLogger(new FileLogger() { EnableAutoLogRemoval = true, EnableMaxFileSizeLimit = true }); + +#if DEBUG LogManager.RegisterLogger(new VSOutputLogger()); +#endif //Configure machine operator logger. var operatorLogger = MachineOperator.EmbeddedLogManager.RegisteredLoggers.SingleOrDefault(x => x is FileLogger) as FileLogger; @@ -65,8 +69,9 @@ namespace Tango.PPC.UI operatorLogger.EnableMaxFileSizeLimit = true; } - LogManager.Log("Application Started..."); - LogManager.Log($"Application Version: '{AssemblyHelper.GetCurrentAssemblyVersion()}'."); + + LogsHelper.SetLogSafe(LogManager.CreateLogSafe()); + LogManager.Log($"Application Started... Version: '{AssemblyHelper.GetCurrentAssemblyVersion()}'."); base.OnStartup(e); 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); } } + + /// <summary> + /// Creates a new log safe which can be used to keep logs and then be disposed. + /// </summary> + /// <returns></returns> + 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<LogItemBase> Logs { get; set; } + + public LogSafe(LogManager logManager) + { + _logManager = logManager; + Logs = new List<LogItemBase>(); + logManager.NewLog += LogManager_NewLog; + } + + private void LogManager_NewLog(object sender, LogItemBase log) + { + Logs.Add(log); + } + + public List<LogItemBase> 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 @@ <Compile Include="LogCategory.cs" /> <Compile Include="LogItemBase.cs" /> <Compile Include="LogManager.cs" /> + <Compile Include="LogSafe.cs" /> <Compile Include="MessageLogItem.cs" /> <Compile Include="ApplicationLogFileParser.cs" /> <Compile Include="ILogFileParser.cs" /> @@ -82,7 +83,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file |
