feat: JSON conversion improvements for log items

This commit is contained in:
Chris Cameron
2020-06-01 11:35:41 -04:00
parent 28ea05e2f6
commit 9deafaec9b

View File

@@ -1,5 +1,6 @@
using System; using System;
using ICD.Common.Properties; using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ICD.Common.Utils.Services.Logging namespace ICD.Common.Utils.Services.Logging
{ {
@@ -17,12 +18,12 @@ namespace ICD.Common.Utils.Services.Logging
/// <summary> /// <summary>
/// Gets the log time in UTC. /// Gets the log time in UTC.
/// </summary> /// </summary>
[PublicAPI]
public DateTime Timestamp { get { return m_Timestamp; } } public DateTime Timestamp { get { return m_Timestamp; } }
/// <summary> /// <summary>
/// Get/Set for severity level. /// Get/Set for severity level.
/// </summary> /// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public eSeverity Severity { get { return m_Severity; } } public eSeverity Severity { get { return m_Severity; } }
/// <summary> /// <summary>
@@ -40,10 +41,22 @@ namespace ICD.Common.Utils.Services.Logging
/// <param name="severity">Severity Level, between 0 and 7</param> /// <param name="severity">Severity Level, between 0 and 7</param>
/// <param name="message">Error message text</param> /// <param name="message">Error message text</param>
public LogItem(eSeverity severity, string message) public LogItem(eSeverity severity, string message)
: this(IcdEnvironment.GetUtcTime(), severity, message)
{
}
/// <summary>
/// Creates a new LogItem object with the specified values.
/// </summary>
/// <param name="timestamp"></param>
/// <param name="severity">Severity Level, between 0 and 7</param>
/// <param name="message">Error message text</param>
[JsonConstructor]
public LogItem(DateTime timestamp, eSeverity severity, string message)
{ {
m_Severity = severity; m_Severity = severity;
m_Message = message; m_Message = message;
m_Timestamp = IcdEnvironment.GetUtcTime(); m_Timestamp = timestamp;
} }
#endregion #endregion
@@ -72,6 +85,11 @@ namespace ICD.Common.Utils.Services.Logging
return !a1.Equals(a2); return !a1.Equals(a2);
} }
/// <summary>
/// Returns true if this instance is equal to the given object.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool Equals(LogItem other) public bool Equals(LogItem other)
{ {
return m_Severity == other.m_Severity && return m_Severity == other.m_Severity &&