From 07e686eb253ffd29f36dbe530b3a17633e02b353 Mon Sep 17 00:00:00 2001 From: Roy Date: Sat, 10 Feb 2018 02:13:37 +0200 Subject: Added support for motor controllers. --- .../Visual_Studio/Tango.Logging/ConsoleLogger.cs | 15 +------ Software/Visual_Studio/Tango.Logging/FileLogger.cs | 11 +----- Software/Visual_Studio/Tango.Logging/ILogger.cs | 12 ++---- Software/Visual_Studio/Tango.Logging/LogManager.cs | 31 +++------------ .../Tango.Logging/SimpleStringLogger.cs | 46 ++++++++++++++++++++++ .../Tango.Logging/Tango.Logging.csproj | 1 + .../Visual_Studio/Tango.Logging/VSOutputLogger.cs | 12 +----- 7 files changed, 58 insertions(+), 70 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Logging/SimpleStringLogger.cs (limited to 'Software/Visual_Studio/Tango.Logging') diff --git a/Software/Visual_Studio/Tango.Logging/ConsoleLogger.cs b/Software/Visual_Studio/Tango.Logging/ConsoleLogger.cs index 4eb77be5a..d073f81ed 100644 --- a/Software/Visual_Studio/Tango.Logging/ConsoleLogger.cs +++ b/Software/Visual_Studio/Tango.Logging/ConsoleLogger.cs @@ -37,24 +37,11 @@ namespace Tango.Logging Immediate = true; } - /// - /// Called when a new library exception is available. - /// - /// The output. - public void OnError(LogItemBase output) - { - EnsureConsoleOpen(() => - { - console.SetColor(ConsoleColor.Red); - console.WriteLine(output.ToString()); - }); - } - /// /// Called when a new library trace is available. /// /// The output. - public void OnTrace(LogItemBase output) + public void OnLog(LogItemBase output) { EnsureConsoleOpen(() => { diff --git a/Software/Visual_Studio/Tango.Logging/FileLogger.cs b/Software/Visual_Studio/Tango.Logging/FileLogger.cs index ca17aa367..75c6e529e 100644 --- a/Software/Visual_Studio/Tango.Logging/FileLogger.cs +++ b/Software/Visual_Studio/Tango.Logging/FileLogger.cs @@ -45,16 +45,7 @@ namespace Tango.Logging /// Called when a new library trace is available. /// /// The output. - public void OnTrace(LogItemBase output) - { - OnError(output); - } - - /// - /// Called when a new library exception is available. - /// - /// The output. - public void OnError(LogItemBase output) + public void OnLog(LogItemBase output) { File.AppendAllText(LogFile, output.ToString() + Environment.NewLine); } diff --git a/Software/Visual_Studio/Tango.Logging/ILogger.cs b/Software/Visual_Studio/Tango.Logging/ILogger.cs index 61108962a..de3c3584b 100644 --- a/Software/Visual_Studio/Tango.Logging/ILogger.cs +++ b/Software/Visual_Studio/Tango.Logging/ILogger.cs @@ -12,16 +12,10 @@ namespace Tango.Logging public interface ILogger { /// - /// Called when a new library trace is available. + /// Called when a new log is available. /// - /// The output. - void OnTrace(LogItemBase output); - - /// - /// Called when a new library exception is available. - /// - /// The output. - void OnError(LogItemBase output); + /// The log. + void OnLog(LogItemBase log); /// /// Gets or sets a value indicating whether this is enabled. diff --git a/Software/Visual_Studio/Tango.Logging/LogManager.cs b/Software/Visual_Studio/Tango.Logging/LogManager.cs index d6750ce0b..43f40fcbe 100644 --- a/Software/Visual_Studio/Tango.Logging/LogManager.cs +++ b/Software/Visual_Studio/Tango.Logging/LogManager.cs @@ -156,14 +156,7 @@ namespace Tango.Logging { if (log != null) { - if (log.GetType() == typeof(ExceptionLogItem)) - { - _loggers.Where(x => x.Enabled && x.Immediate).ToList().ForEach(x => x.OnError(log)); - } - else - { - _loggers.Where(x => x.Enabled && x.Immediate).ToList().ForEach(x => x.OnTrace(log)); - } + _loggers.Where(x => x.Enabled && x.Immediate).ToList().ForEach(x => x.OnLog(log)); } _logs.Enqueue(log); @@ -187,8 +180,8 @@ namespace Tango.Logging /// /// Loggings thread method. /// - [DebuggerStepThrough] - [DebuggerHidden] + //[DebuggerStepThrough] + //[DebuggerHidden] private static void LoggingThreadMethod() { while (_logs.Count > 0) @@ -199,14 +192,7 @@ namespace Tango.Logging { if (log != null) { - if (log.GetType() == typeof(ExceptionLogItem)) - { - _loggers.Where(x => x.Enabled && !x.Immediate).ToList().ForEach(x => x.OnError(log)); - } - else - { - _loggers.Where(x => x.Enabled && !x.Immediate).ToList().ForEach(x => x.OnTrace(log)); - } + _loggers.Where(x => x.Enabled && !x.Immediate).ToList().ForEach(x => x.OnLog(log)); } } @@ -238,14 +224,7 @@ namespace Tango.Logging { try { - if (log.GetType() == typeof(ExceptionLogItem)) - { - _loggers.Where(x => x.Enabled).ToList().ForEach(x => x.OnError(log)); - } - else - { - _loggers.Where(x => x.Enabled).ToList().ForEach(x => x.OnTrace(log)); - } + _loggers.Where(x => x.Enabled).ToList().ForEach(x => x.OnLog(log)); wroteLog = true; } diff --git a/Software/Visual_Studio/Tango.Logging/SimpleStringLogger.cs b/Software/Visual_Studio/Tango.Logging/SimpleStringLogger.cs new file mode 100644 index 000000000..57aea174f --- /dev/null +++ b/Software/Visual_Studio/Tango.Logging/SimpleStringLogger.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Logging +{ + public class SimpleStringLogger : ILogger + { + private bool _enabled; + private bool _immidiate; + + public bool Enabled { get => _enabled; set => _enabled = value; } + public bool Immediate { get => _immidiate; set => _immidiate = value; } + + public List Categories { get; set; } + + public event EventHandler LogReceived; + + public SimpleStringLogger() + { + Categories = new List(); + Categories.Add(LogCategory.Critical); + Categories.Add(LogCategory.Debug); + Categories.Add(LogCategory.Error); + Categories.Add(LogCategory.General); + Categories.Add(LogCategory.Warning); + Enabled = true; + } + + public SimpleStringLogger(params LogCategory[] categories) + { + Categories = categories.ToList(); + Enabled = true; + } + + public void OnLog(LogItemBase log) + { + if (Categories.Contains(log.Category)) + { + LogReceived?.Invoke(this, log); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj b/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj index 1e70e4cb1..04a651de8 100644 --- a/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj +++ b/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj @@ -64,6 +64,7 @@ + diff --git a/Software/Visual_Studio/Tango.Logging/VSOutputLogger.cs b/Software/Visual_Studio/Tango.Logging/VSOutputLogger.cs index 80de5292f..3804bdaa3 100644 --- a/Software/Visual_Studio/Tango.Logging/VSOutputLogger.cs +++ b/Software/Visual_Studio/Tango.Logging/VSOutputLogger.cs @@ -25,21 +25,11 @@ namespace Tango.Logging /// Called when a new library trace is available. /// /// The output. - public void OnTrace(LogItemBase output) + public void OnLog(LogItemBase output) { Debug.WriteLine(output.ToString()); } - /// - /// Called when a new library exception is available. - /// - /// The output. - public void OnError(LogItemBase output) - { - Debug.WriteLine(output.ToString()); - } - - private bool _isEnabled; /// /// Gets or sets a value indicating whether this is enabled. -- cgit v1.3.1