/// <summary> /// Computes an MD5 hash code for the log entry /// </summary> /// <param name="extension">The extended entry information (or <c>null</c>).</param> /// <param name="entryType">The log entry type.</param> /// <param name="message">The log message (or <c>null</c>).</param> /// <param name="e">The logged exception (or <c>null</c>).</param> /// <returns>The computed hash.</returns> private static MD5Key ComputeMD5Hash(ISysLogEntryExtension extension, SysLogEntryType entryType, string message, Exception e) { StringBuilder sb = new StringBuilder(1024); if (extension != null) { sb.Append(extension.Format()); } sb.Append('\t'); sb.Append(entryType.ToString()); sb.Append('\t'); if (message != null) { sb.Append(message); } sb.Append('\t'); if (e != null) { sb.Append(e.GetType().FullName); sb.Append('\t'); sb.Append(e.Message); sb.Append('\t'); sb.Append(e.StackTrace.ToString()); } return(new MD5Key(MD5Hasher.Compute(sb.ToString()))); }
/// <summary> /// Renders the log entry into a string. /// </summary> /// <param name="format">The formatting option flags.</param> /// <returns>The formatted string.</returns> public string ToString(SysLogEntryFormat format) { var sb = new StringBuilder(); if ((format & SysLogEntryFormat.ShowBar) != 0) { sb.Append("=================================\r\n"); } if ((format & SysLogEntryFormat.ShowTime) != 0) { sb.AppendFormat((IFormatProvider)null, "Time: {0} UTC\r\n", Time.ToString("MM-dd-yyyy HH:mm:ss.fff")); } if (this.Message != null) { sb.Append(Message); sb.Append("\r\n"); } if (Extension != null && (format & SysLogEntryFormat.ShowExtended) != 0) { sb.AppendFormat((IFormatProvider)null, Extension.Format()); } if (this.Exception != null) { AppendException(sb, this.Exception); } else if (this.Category != null) { if ((format & SysLogEntryFormat.ShowType) != 0) { sb.AppendFormat((IFormatProvider)null, "{0}: {1}\r\n", Type.ToString(), Category); } else { sb.AppendFormat((IFormatProvider)null, "{0}\r\n", Category); } } else { if ((format & SysLogEntryFormat.ShowType) != 0) { sb.AppendFormat((IFormatProvider)null, "{0}:\r\n", Type.ToString()); } } return(sb.ToString()); }