diff options
| author | Roy <roy.mail.net@gmail.com> | 2018-02-10 02:13:37 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2018-02-10 02:13:37 +0200 |
| commit | 07e686eb253ffd29f36dbe530b3a17633e02b353 (patch) | |
| tree | d9663f1c92a400349dffc743adb0114ee1a7f618 /Software/Visual_Studio/Tango.Logging | |
| parent | c8c9606e545f49aae3d9f0524775436adbdf27e9 (diff) | |
| download | Tango-07e686eb253ffd29f36dbe530b3a17633e02b353.tar.gz Tango-07e686eb253ffd29f36dbe530b3a17633e02b353.zip | |
Added support for motor controllers.
Diffstat (limited to 'Software/Visual_Studio/Tango.Logging')
7 files changed, 58 insertions, 70 deletions
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 @@ -38,23 +38,10 @@ namespace Tango.Logging } /// <summary> - /// Called when a new library exception is available. - /// </summary> - /// <param name="output">The output.</param> - public void OnError(LogItemBase output) - { - EnsureConsoleOpen(() => - { - console.SetColor(ConsoleColor.Red); - console.WriteLine(output.ToString()); - }); - } - - /// <summary> /// Called when a new library trace is available. /// </summary> /// <param name="output">The output.</param> - 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. /// </summary> /// <param name="output">The output.</param> - public void OnTrace(LogItemBase output) - { - OnError(output); - } - - /// <summary> - /// Called when a new library exception is available. - /// </summary> - /// <param name="output">The output.</param> - 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 { /// <summary> - /// Called when a new library trace is available. + /// Called when a new log is available. /// </summary> - /// <param name="output">The output.</param> - void OnTrace(LogItemBase output); - - /// <summary> - /// Called when a new library exception is available. - /// </summary> - /// <param name="output">The output.</param> - void OnError(LogItemBase output); + /// <param name="log">The log.</param> + void OnLog(LogItemBase log); /// <summary> /// Gets or sets a value indicating whether this <see cref="ILogger"/> 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 /// <summary> /// Loggings thread method. /// </summary> - [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<LogCategory> Categories { get; set; } + + public event EventHandler<LogItemBase> LogReceived; + + public SimpleStringLogger() + { + Categories = new List<LogCategory>(); + 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 @@ <Compile Include="LogManager.cs" /> <Compile Include="MessageLogItem.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="SimpleStringLogger.cs" /> <Compile Include="VSOutputLogger.cs" /> </ItemGroup> <ItemGroup> 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. /// </summary> /// <param name="output">The output.</param> - public void OnTrace(LogItemBase output) + public void OnLog(LogItemBase output) { Debug.WriteLine(output.ToString()); } - /// <summary> - /// Called when a new library exception is available. - /// </summary> - /// <param name="output">The output.</param> - public void OnError(LogItemBase output) - { - Debug.WriteLine(output.ToString()); - } - - private bool _isEnabled; /// <summary> /// Gets or sets a value indicating whether this <see cref="ILogger" /> is enabled. |
