using System; using System.Text; using ICD.Common.Properties; using ICD.Common.Utils; namespace ICD.Common.Services.Logging { /// /// Log Entry Item /// public struct LogItem { private readonly string m_Message; private readonly eSeverity m_Severity; private readonly DateTime m_Timestamp; #region Properties /// /// Accessor only for timestamp. /// [PublicAPI] public DateTime Timestamp { get { return m_Timestamp; } } /// /// Get/Set for severity level. /// public eSeverity Severity { get { return m_Severity; } } /// /// Get/Set for message string. /// public string Message { get { return m_Message; } } #endregion #region Constructors /// /// Creates a new LogItem object with the specified values. /// /// Severity Level, between 0 and 7 /// Error message text public LogItem(eSeverity severity, string message) { m_Severity = severity; m_Message = message; m_Timestamp = IcdEnvironment.GetLocalTime(); } #endregion #region Methods /// /// Return the text format to send to Fusion /// /// text format for fusion, including timestamp, severity, and message [PublicAPI] public string GetFusionLogText() { StringBuilder s = new StringBuilder(); s.Append(Timestamp.ToString("yyyyMMddHHmmss")); s.Append("||"); s.Append((int)Severity); s.Append("||"); s.Append(Message); return s.ToString(); } /// /// Implementing default equality. /// /// /// /// public static bool operator ==(LogItem a1, LogItem a2) { return a1.Equals(a2); } /// /// Implementing default inequality. /// /// /// /// public static bool operator !=(LogItem a1, LogItem a2) { return !(a1 == a2); } /// /// Returns true if this instance is equal to the given object. /// /// /// public override bool Equals(object other) { if (other == null || GetType() != other.GetType()) return false; return GetHashCode() == ((LogItem)other).GetHashCode(); } /// /// Gets the hashcode for this instance. /// /// public override int GetHashCode() { unchecked { int hash = 17; hash = hash * 23 + (m_Message == null ? 0 : m_Message.GetHashCode()); hash = hash * 23 + (int)m_Timestamp.Ticks; hash = hash * 23 + (int)m_Severity; return hash; } } #endregion } }