aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Logging
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-02-07 13:51:08 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-02-07 13:51:08 +0200
commit6e082b1d9d7b4c5888e7e7345e148eb944b8c624 (patch)
tree583efc08780196dbb3ae5fac714125b8e41387ae /Software/Visual_Studio/Tango.Logging
parent942a428f90587a9ffdafaa593b780fb6ad06aabc (diff)
downloadTango-6e082b1d9d7b4c5888e7e7345e148eb944b8c624.tar.gz
Tango-6e082b1d9d7b4c5888e7e7345e148eb944b8c624.zip
Added logging categories!!!
Diffstat (limited to 'Software/Visual_Studio/Tango.Logging')
-rw-r--r--Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs2
-rw-r--r--Software/Visual_Studio/Tango.Logging/LogCategory.cs20
-rw-r--r--Software/Visual_Studio/Tango.Logging/LogItemBase.cs5
-rw-r--r--Software/Visual_Studio/Tango.Logging/LogManager.cs39
-rw-r--r--Software/Visual_Studio/Tango.Logging/MessageLogItem.cs2
-rw-r--r--Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj1
6 files changed, 66 insertions, 3 deletions
diff --git a/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs b/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs
index acebc2856..d9bb8b6a7 100644
--- a/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs
+++ b/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs
@@ -36,7 +36,7 @@ namespace Tango.Logging
/// </summary>
public override string ToString()
{
- return String.Format("[{0}] [{1}] [{2}] [Line {3}]: {4}{5}", TimeStamp.ToString("HH:mm:ss.ff"), Path.GetFileNameWithoutExtension(CallerFile), CallerMethodName, CallerLineNumber, Description, Environment.NewLine + InnerException.Message);
+ return String.Format("[{0}] [{6}] [{1}] [{2}] [Line {3}]: {4}{5}", TimeStamp.ToString("HH:mm:ss.ff"), Path.GetFileNameWithoutExtension(CallerFile), CallerMethodName, CallerLineNumber, Description, Environment.NewLine + InnerException.Message, Category);
}
}
diff --git a/Software/Visual_Studio/Tango.Logging/LogCategory.cs b/Software/Visual_Studio/Tango.Logging/LogCategory.cs
new file mode 100644
index 000000000..f33190e2c
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Logging/LogCategory.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Logging
+{
+ /// <summary>
+ /// Represents the different logging categories.
+ /// </summary>
+ public enum LogCategory
+ {
+ General = 1,
+ Debug = 2,
+ Warning = 4,
+ Error = 8,
+ Critical = 16,
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Logging/LogItemBase.cs b/Software/Visual_Studio/Tango.Logging/LogItemBase.cs
index aab78c63d..85451488a 100644
--- a/Software/Visual_Studio/Tango.Logging/LogItemBase.cs
+++ b/Software/Visual_Studio/Tango.Logging/LogItemBase.cs
@@ -32,6 +32,11 @@ namespace Tango.Logging
public DateTime TimeStamp { get; set; }
/// <summary>
+ /// Gets or sets the log category.
+ /// </summary>
+ public LogCategory Category { get; set; }
+
+ /// <summary>
/// Gets the log message.
/// </summary>
/// <returns></returns>
diff --git a/Software/Visual_Studio/Tango.Logging/LogManager.cs b/Software/Visual_Studio/Tango.Logging/LogManager.cs
index 3ada76104..0fe1e11b3 100644
--- a/Software/Visual_Studio/Tango.Logging/LogManager.cs
+++ b/Software/Visual_Studio/Tango.Logging/LogManager.cs
@@ -33,9 +33,21 @@ namespace Tango.Logging
{
_loggers = new List<ILogger>();
_logs = new ConcurrentQueue<LogItemBase>();
+ Categories = new List<LogCategory>();
+
+ Categories.Add(LogCategory.Critical);
+ Categories.Add(LogCategory.Debug);
+ Categories.Add(LogCategory.Error);
+ Categories.Add(LogCategory.General);
+ Categories.Add(LogCategory.Warning);
}
/// <summary>
+ /// Gets or sets the logging categories filter.
+ /// </summary>
+ public static List<LogCategory> Categories { get; private set; }
+
+ /// <summary>
/// Registers a logger.
/// </summary>
/// <param name="logger">The logger.</param>
@@ -66,12 +78,25 @@ namespace Tango.Logging
/// <param name="description">Error description.</param>
public static Exception Log(Exception e, String description = null, [CallerMemberName] string caller = null, [CallerFilePath] string file = null, [CallerLineNumber] int lineNumber = 0)
{
+ return Log(e, LogCategory.Error, description, caller, file, lineNumber);
+ }
+
+ /// <summary>
+ /// Add new exception log item.
+ /// </summary>
+ /// <param name="e">Exception.</param>
+ /// <param name="description">Error description.</param>
+ public static Exception Log(Exception e, LogCategory category, String description = null, [CallerMemberName] string caller = null, [CallerFilePath] string file = null, [CallerLineNumber] int lineNumber = 0)
+ {
+ if (!Categories.Contains(category)) return e;
+
ExceptionLogItem log = new ExceptionLogItem();
log.CallerMethodName = caller;
log.CallerFile = file;
log.CallerLineNumber = lineNumber;
log.TimeStamp = DateTime.Now;
log.InnerException = e;
+ log.Category = category;
log.Description = description != null ? description : e.ToString();
if (!OverrideQueue)
@@ -92,11 +117,23 @@ namespace Tango.Logging
/// <param name="message">Message.</param>
public static void Log(String message, [CallerMemberName] string caller = null, [CallerFilePath] string file = null, [CallerLineNumber] int lineNumber = 0)
{
+ Log(message, LogCategory.General, caller, file, lineNumber);
+ }
+
+ /// <summary>
+ /// Add new message log item.
+ /// </summary>
+ /// <param name="message">Message.</param>
+ public static void Log(String message, LogCategory category, [CallerMemberName] string caller = null, [CallerFilePath] string file = null, [CallerLineNumber] int lineNumber = 0)
+ {
+ if (!Categories.Contains(category)) return;
+
MessageLogItem log = new MessageLogItem();
log.CallerMethodName = caller;
log.CallerFile = file;
log.CallerLineNumber = lineNumber;
log.TimeStamp = DateTime.Now;
+ log.Category = category;
log.Message = message;
if (!OverrideQueue)
@@ -210,7 +247,7 @@ namespace Tango.Logging
wroteLog = true;
}
- catch
+ catch
{
Thread.Sleep(5);
}
diff --git a/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs b/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs
index 445706779..f7d7e004c 100644
--- a/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs
+++ b/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs
@@ -31,7 +31,7 @@ namespace Tango.Logging
/// </summary>
public override string ToString()
{
- return String.Format("[{0}] [{1}] [{2}] [Line {3}]: {4}", TimeStamp.ToString("HH:mm:ss.ff"), Path.GetFileNameWithoutExtension(CallerFile), CallerMethodName, CallerLineNumber, Message);
+ return String.Format("[{0}] [{5}] [{1}] [{2}] [Line {3}]: {4}", TimeStamp.ToString("HH:mm:ss.ff"), Path.GetFileNameWithoutExtension(CallerFile), CallerMethodName, CallerLineNumber, Message, Category);
}
}
}
diff --git a/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj b/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj
index 93d0cd4ea..1e70e4cb1 100644
--- a/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj
+++ b/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj
@@ -59,6 +59,7 @@
<Compile Include="GlobalExceptionTrapper.cs" />
<Compile Include="IGlobalExceptionTrapper.cs" />
<Compile Include="ILogger.cs" />
+ <Compile Include="LogCategory.cs" />
<Compile Include="LogItemBase.cs" />
<Compile Include="LogManager.cs" />
<Compile Include="MessageLogItem.cs" />