ErrorLogEntry.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #region --------------- Copyright Dresser Wayne Pignone -------------
  2. /*
  3. * $Log: /Wrk/WayneLibraries/Wrk/Log/ErrorLogEntry.cs $
  4. *
  5. * 2 08-02-13 9:26 Mattias.larsson
  6. * FxCop fixes.
  7. */
  8. #endregion
  9. using System.Text;
  10. using System.Diagnostics.CodeAnalysis;
  11. namespace Wayne.Lib.Log
  12. {
  13. /// <summary>
  14. /// Base LogEntry for Errors.
  15. /// </summary>
  16. public class ErrorLogEntry : EventLogEntry
  17. {
  18. #region Fields
  19. private ErrorLogSeverity severity;
  20. #endregion
  21. #region Construction
  22. /// <summary>
  23. /// Constructor.
  24. /// </summary>
  25. /// <param name="entity"></param>
  26. /// <param name="severity"></param>
  27. /// <param name="logObject">The object to log.</param>
  28. [SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "object")]
  29. public ErrorLogEntry(IIdentifiableEntity entity, ErrorLogSeverity severity, object logObject)
  30. : base(entity, logObject)
  31. {
  32. this.severity = severity;
  33. }
  34. /// <summary>
  35. /// Constructor.
  36. /// </summary>
  37. /// <param name="entity"></param>
  38. /// <param name="severity"></param>
  39. /// <param name="logObject">The object to log.</param>
  40. /// <param name="category"></param>
  41. [SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "object")]
  42. public ErrorLogEntry(IIdentifiableEntity entity, ErrorLogSeverity severity, object logObject, object category)
  43. : base(entity, logObject, category)
  44. {
  45. this.severity = severity;
  46. }
  47. #endregion
  48. #region Properties
  49. /// <summary>
  50. /// The keyword "***ERROR" put in the log file.
  51. /// </summary>
  52. public const string LogPrefix = "***ERROR";
  53. /// <summary>
  54. /// The severity of the error.
  55. /// </summary>
  56. public ErrorLogSeverity Severity
  57. {
  58. get { return severity; }
  59. }
  60. #endregion
  61. #region Methods: AppendTextToStringBuilder
  62. /// <summary>
  63. /// Appends the object to log to a StringBuilder-output.
  64. /// </summary>
  65. /// <param name="logWriter">The logwriter to be used for logging.</param>
  66. /// <param name="output">The StringBuilder.</param>
  67. /// <param name="indentLength">The indent to be used if many lines.</param>
  68. /// <param name="isFirstLine">Is this the first line to log?</param>
  69. /// <param name="indent">A string holding a generated indent-text (=a number of spaces). Use AppendIndent() to append the indent.</param>
  70. internal override void AppendToStringBuilder(LogWriter logWriter, StringBuilder output,
  71. int indentLength, ref bool isFirstLine, ref string indent)
  72. {
  73. // Add the keyword.
  74. output.Append(LogPrefix);
  75. output.Append(": ");
  76. // Add the generic entry info.
  77. StringLogObject.AppendObjectToStringBuilder(LogObject, output, logWriter, indentLength, ref isFirstLine, ref indent);
  78. }
  79. #endregion
  80. }
  81. }