From 9deafaec9bae3779e4d86787a80dcc4e7fc3f927 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Mon, 1 Jun 2020 11:35:41 -0400 Subject: [PATCH] feat: JSON conversion improvements for log items --- ICD.Common.Utils/Services/Logging/LogItem.cs | 24 +++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/ICD.Common.Utils/Services/Logging/LogItem.cs b/ICD.Common.Utils/Services/Logging/LogItem.cs index 0d217a1..c4f9784 100644 --- a/ICD.Common.Utils/Services/Logging/LogItem.cs +++ b/ICD.Common.Utils/Services/Logging/LogItem.cs @@ -1,5 +1,6 @@ using System; -using ICD.Common.Properties; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace ICD.Common.Utils.Services.Logging { @@ -17,12 +18,12 @@ namespace ICD.Common.Utils.Services.Logging /// /// Gets the log time in UTC. /// - [PublicAPI] public DateTime Timestamp { get { return m_Timestamp; } } /// /// Get/Set for severity level. /// + [JsonConverter(typeof(StringEnumConverter))] public eSeverity Severity { get { return m_Severity; } } /// @@ -40,10 +41,22 @@ namespace ICD.Common.Utils.Services.Logging /// Severity Level, between 0 and 7 /// Error message text public LogItem(eSeverity severity, string message) + : this(IcdEnvironment.GetUtcTime(), severity, message) + { + } + + /// + /// Creates a new LogItem object with the specified values. + /// + /// + /// Severity Level, between 0 and 7 + /// Error message text + [JsonConstructor] + public LogItem(DateTime timestamp, eSeverity severity, string message) { m_Severity = severity; m_Message = message; - m_Timestamp = IcdEnvironment.GetUtcTime(); + m_Timestamp = timestamp; } #endregion @@ -72,6 +85,11 @@ namespace ICD.Common.Utils.Services.Logging return !a1.Equals(a2); } + /// + /// Returns true if this instance is equal to the given object. + /// + /// + /// public bool Equals(LogItem other) { return m_Severity == other.m_Severity &&