123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- #region --------------- Copyright Dresser Wayne Pignone -------------
- /*
- * $Log: /Wrk/WayneLibraries/Wrk/Log/ExceptionLogEntry.cs $
- *
- * 3 08-02-13 9:26 Mattias.larsson
- * FxCop fixes.
- */
- #endregion
- using System;
- using System.Text;
- using System.Diagnostics.CodeAnalysis;
- namespace Wayne.Lib.Log
- {
- /// <summary>
- /// Log entry for exception errors.
- /// </summary>
- public class ExceptionLogEntry : ErrorLogEntry
- {
- #region Fields
- private Exception exception;
- #endregion
- #region Construction
- /// <summary>
- /// Constructor.
- /// </summary>
- /// <param name="entity"></param>
- /// <param name="severity"></param>
- /// <param name="logObject">The object to log.</param>
- /// <param name="exception"></param>
- [SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "object")]
- public ExceptionLogEntry(IIdentifiableEntity entity, ErrorLogSeverity severity, object logObject, Exception exception)
- : base(entity, severity, logObject)
- {
- this.exception = exception;
- }
- /// <summary>
- /// Constructor.
- /// </summary>
- /// <param name="entity"></param>
- /// <param name="severity"></param>
- /// <param name="logObject">The object to log.</param>
- /// <param name="category"></param>
- /// <param name="exception"></param>
- [SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "object")]
- public ExceptionLogEntry(IIdentifiableEntity entity, ErrorLogSeverity severity, object logObject, object category, Exception exception)
- : base(entity, severity, logObject, category)
- {
- this.exception = exception;
- }
- #endregion
- #region Properties
- /// <summary>
- /// Exception information.
- /// </summary>
- public Exception Exception
- {
- get { return exception; }
- }
- #endregion
- #region Methods: AppendTextToStringBuilder
- /// <summary>
- /// Appends the object to log to a StringBuilder-output.
- /// </summary>
- /// <param name="logWriter">The logwriter to be used for logging.</param>
- /// <param name="output">The StringBuilder.</param>
- /// <param name="indentLength">The indent to be used if many lines.</param>
- /// <param name="isFirstLine">Is this the first line to log?</param>
- /// <param name="indent">A string holding a generated indent-text (=a number of spaces). Use AppendIndent() to append the indent.</param>
- internal override void AppendToStringBuilder(LogWriter logWriter, StringBuilder output,
- int indentLength, ref bool isFirstLine, ref string indent)
- {
- base.AppendToStringBuilder(logWriter, output, indentLength, ref isFirstLine, ref indent);
- // Add the exception.
- if (exception != null)
- {
- StringLogObject.EnsureIndent(indentLength, ref indent);
- string headerText = "Exception: ";
- Exception ex = exception;
- while (ex != null)
- {
- StringLogObject.AppendStringToStringBuilder(headerText + ex.ToString(), output, logWriter, indentLength, ref isFirstLine, ref indent);
- // Check if there is an inner exception
- ex = ex.InnerException;
- if (ex != null)
- {
- // Indent 3 more spaces.
- indent += " ";
- headerText = "Inner Exception: ";
- }
- }
-
-
- //StringLogObject.AppendStringToStringBuilder("Exception: ", output, logWriter, indentLength, true, ref indent);
- //string newLineString = "\r\n" + Wayne.Lib.Strings.Indent(indentLength, true);
- //output.Append(newLineString);
- //output.Append("Exception: ");
- //Exception ex = exception;
- //while (ex != null)
- //{
- // StringLogObject.AppendObjectToStringBuilder(ex.Message, output, logWriter, indentLength, false, ref indent);
- // // Check if there is an inner exception
- // ex = ex.InnerException;
- // if (ex != null)
- // {
- // // Indent 3 more spaces.
- // newLineString += " ";
- // indentLength += 3;
- // output.Append(newLineString);
- // output.Append("Inner Exception: ");
- // }
- //}
- }
- }
- #endregion
- }
- }
|