/// <summary> /// Reads the exception fields from the specified log file reader. /// </summary> /// <param name="reader">The log file reader to read from.</param> /// <returns>The exception data.</returns> internal static FieldLogException Read(FieldLogFileReader reader) { FieldLogException ex = new FieldLogException(); ex.Type = reader.ReadString(); if (reader.FormatVersion >= 2) { ex.TypeModule = reader.ReadString(); ex.Token = reader.ReadInt32(); } ex.Message = reader.ReadString(); ex.Code = reader.ReadInt32(); ex.Data = reader.ReadString(); int frameCount = reader.ReadInt32(); ex.StackFrames = new FieldLogStackFrame[frameCount]; for (int i = 0; i < frameCount; i++) { ex.StackFrames[i] = FieldLogStackFrame.Read(reader); } int innerCount = reader.ReadInt32(); ex.InnerExceptions = new FieldLogException[innerCount]; for (int i = 0; i < innerCount; i++) { ex.InnerExceptions[i] = FieldLogException.Read(reader); } return(ex); }
public FieldLogStackFrameViewModel(FieldLogStackFrame stackFrame) { StackFrame = stackFrame; // Initially format source string Refresh(); }
/// <summary> /// Reads the stack frame fields from the specified log file reader. /// </summary> /// <param name="reader">The log file reader to read from.</param> /// <returns>The stack frame data.</returns> internal static FieldLogStackFrame Read(FieldLogFileReader reader) { FieldLogStackFrame frame = new FieldLogStackFrame(); frame.Module = reader.ReadString(); if (reader.FormatVersion >= 2) { frame.Token = reader.ReadInt32(); frame.ILOffset = reader.ReadInt32(); } frame.TypeName = reader.ReadString(); frame.MethodName = reader.ReadString(); frame.MethodSignature = reader.ReadString(); frame.FileName = reader.ReadString(); frame.Line = reader.ReadInt32(); frame.Column = reader.ReadInt32(); return(frame); }
/// <summary> /// Initialises a new instance of the FieldLogException class. /// </summary> /// <param name="ex">The Exception instance.</param> /// <param name="customStackTrace">A StackTrace that shall be logged instead of the StackTrace from the Exception instance.</param> public FieldLogException(Exception ex, StackTrace customStackTrace) { Exception = ex; Type exType = ex.GetType(); Type = exType.FullName; if (!exType.Module.Name.Contains("<")) { TypeModule = exType.Module.FullyQualifiedName; } else { TypeModule = exType.Module.Name; } Token = exType.MetadataToken; Message = ex.Message.TrimEnd(); StackTrace stackTrace = customStackTrace; if (stackTrace == null) { stackTrace = new StackTrace(ex, true); } StackFrames = new FieldLogStackFrame[stackTrace.FrameCount]; for (int i = 0; i < stackTrace.FrameCount; i++) { StackFrames[i] = new FieldLogStackFrame(stackTrace.GetFrame(i)); } StringBuilder dataSb = new StringBuilder(); if (ex.Data != null) { foreach (DictionaryEntry x in ex.Data) { dataSb.Append("Data[").Append(x.Key).Append("]"); if (x.Value != null) { dataSb.Append(" (") .Append(x.Value.GetType().Name) .Append("): ") .Append(Convert.ToString(x.Value, CultureInfo.InvariantCulture)); } else { dataSb.Append(": null"); } dataSb.Append("\n"); } } // Find more properties through reflection PropertyInfo[] props = exType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo prop in props) { // Known properties, already handled if (prop.Name == "Message") { continue; } if (prop.Name == "StackTrace") { continue; } if (prop.Name == "ErrorCode") { continue; } if (prop.Name == "Data") { continue; } if (prop.Name == "InnerException") { continue; } if (prop.Name == "InnerExceptions") { continue; } if (prop.Name == "TargetSite") { continue; } if (prop.Name == "HelpLink") { continue; } if (prop.Name == "Source") { continue; } try { object value = prop.GetValue(ex, null); // Indexed properties are not supported here! dataSb.Append(prop.Name); if (value != null) { dataSb.Append(" (").Append(value.GetType().Name).Append("): ").Append(Convert.ToString(value, CultureInfo.InvariantCulture)); if (value is byte) { dataSb.Append(" (0x").Append(((byte)value).ToString("X2")).Append(")"); } if (value is sbyte) { dataSb.Append(" (0x").Append(((sbyte)value).ToString("X2")).Append(")"); } if (value is ushort) { dataSb.Append(" (0x").Append(((ushort)value).ToString("X4")).Append(")"); } if (value is short) { dataSb.Append(" (0x").Append(((short)value).ToString("X")).Append(")"); } if (value is uint) { dataSb.Append(" (0x").Append(((uint)value).ToString("X8")).Append(")"); } if (value is int) { dataSb.Append(" (0x").Append(((int)value).ToString("X8")).Append(")"); } if (value is ulong) { dataSb.Append(" (0x").Append(((ulong)value).ToString("X16")).Append(")"); } if (value is long) { dataSb.Append(" (0x").Append(((long)value).ToString("X16")).Append(")"); } if (exType.FullName == "System.Data.Entity.Validation.DbEntityValidationException" && prop.Name == "EntityValidationErrors") { dataSb.Append("\n"); dataSb.Append(FieldLogDataItem.FormatValues(value)); } } else { dataSb.Append(": null"); } dataSb.Append("\n"); } catch (Exception ex2) { dataSb.Append("Exception property \"") .Append(prop.Name) .Append("\" cannot be retrieved. (") .Append(ex2.GetType().Name) .Append(": ") .Append(ex2.Message) .Append(")\n"); } } Data = dataSb.ToString().TrimEnd(); #if !NET20 AggregateException aex = ex as AggregateException; if (aex != null) { InnerExceptions = new FieldLogException[aex.InnerExceptions.Count]; for (int i = 0; i < aex.InnerExceptions.Count; i++) { InnerExceptions[i] = new FieldLogException(aex.InnerExceptions[i]); } } else #endif if (ex.InnerException != null) { InnerExceptions = new FieldLogException[1]; InnerExceptions[0] = new FieldLogException(ex.InnerException); } ExternalException eex = ex as ExternalException; // e.g. COMException if (eex != null) { Code = eex.ErrorCode; } Size = (Type != null ? Type.Length * 2 : 0) + 4 + (Message != null ? Message.Length * 2 : 0) + 4 + (Data != null ? Data.Length * 2 : 0); foreach (FieldLogStackFrame sf in StackFrames) { Size += sf.Size; } if (InnerExceptions != null) { foreach (FieldLogException ex2 in InnerExceptions) { Size += ex2.Size; } } }
/// <summary> /// Initialises a new instance of the FieldLogException class. /// </summary> /// <param name="ex">The Exception instance.</param> /// <param name="customStackTrace">A StackTrace that shall be logged instead of the StackTrace from the Exception instance.</param> public FieldLogException(Exception ex, StackTrace customStackTrace) { Exception = ex; Type exType = ex.GetType(); Type = exType.FullName; TypeModule = exType.Module.FullyQualifiedName; Token = exType.MetadataToken; Message = ex.Message.TrimEnd(); StackTrace stackTrace = customStackTrace; if (stackTrace == null) { stackTrace = new StackTrace(ex, true); } StackFrames = new FieldLogStackFrame[stackTrace.FrameCount]; for (int i = 0; i < stackTrace.FrameCount; i++) { StackFrames[i] = new FieldLogStackFrame(stackTrace.GetFrame(i)); } StringBuilder dataSb = new StringBuilder(); if (ex.Data != null) { foreach (DictionaryEntry x in ex.Data) { dataSb.Append("Data[").Append(x.Key).Append("]"); if (x.Value != null) { dataSb.Append(" (") .Append(x.Value.GetType().Name) .Append("): ") .Append(Convert.ToString(x.Value, CultureInfo.InvariantCulture)); } else { dataSb.Append(": null"); } dataSb.Append("\n"); } } // Find more properties through reflection PropertyInfo[] props = exType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo prop in props) { // Known properties, already handled if (prop.Name == "Message") continue; if (prop.Name == "StackTrace") continue; if (prop.Name == "ErrorCode") continue; if (prop.Name == "Data") continue; if (prop.Name == "InnerException") continue; if (prop.Name == "InnerExceptions") continue; if (prop.Name == "TargetSite") continue; if (prop.Name == "HelpLink") continue; if (prop.Name == "Source") continue; try { object value = prop.GetValue(ex, null); // Indexed properties are not supported here! dataSb.Append(prop.Name); if (value != null) { dataSb.Append(" (").Append(value.GetType().Name).Append("): ").Append(Convert.ToString(value, CultureInfo.InvariantCulture)); if (value is byte) { dataSb.Append(" (0x").Append(((byte)value).ToString("X2")).Append(")"); } if (value is sbyte) { dataSb.Append(" (0x").Append(((sbyte)value).ToString("X2")).Append(")"); } if (value is ushort) { dataSb.Append(" (0x").Append(((ushort)value).ToString("X4")).Append(")"); } if (value is short) { dataSb.Append(" (0x").Append(((short)value).ToString("X")).Append(")"); } if (value is uint) { dataSb.Append(" (0x").Append(((uint)value).ToString("X8")).Append(")"); } if (value is int) { dataSb.Append(" (0x").Append(((int)value).ToString("X8")).Append(")"); } if (value is ulong) { dataSb.Append(" (0x").Append(((ulong)value).ToString("X16")).Append(")"); } if (value is long) { dataSb.Append(" (0x").Append(((long)value).ToString("X16")).Append(")"); } } else { dataSb.Append(": null"); } dataSb.Append("\n"); } catch (Exception ex2) { dataSb.Append("Exception property \"") .Append(prop.Name) .Append("\" cannot be retrieved. (") .Append(ex2.GetType().Name) .Append(": ") .Append(ex2.Message) .Append(")\n"); } } Data = dataSb.ToString().TrimEnd(); #if !NET20 AggregateException aex = ex as AggregateException; if (aex != null) { InnerExceptions = new FieldLogException[aex.InnerExceptions.Count]; for (int i = 0; i < aex.InnerExceptions.Count; i++) { InnerExceptions[i] = new FieldLogException(aex.InnerExceptions[i]); } } else #endif if (ex.InnerException != null) { InnerExceptions = new FieldLogException[1]; InnerExceptions[0] = new FieldLogException(ex.InnerException); } ExternalException eex = ex as ExternalException; // e.g. COMException if (eex != null) { Code = eex.ErrorCode; } Size = (Type != null ? Type.Length * 2 : 0) + 4 + (Message != null ? Message.Length * 2 : 0) + 4 + (Data != null ? Data.Length * 2 : 0); foreach (FieldLogStackFrame sf in StackFrames) { Size += sf.Size; } if (InnerExceptions != null) { foreach (FieldLogException ex2 in InnerExceptions) { Size += ex2.Size; } } }
/// <summary> /// Reads the stack frame fields from the specified log file reader. /// </summary> /// <param name="reader">The log file reader to read from.</param> /// <returns>The stack frame data.</returns> internal static FieldLogStackFrame Read(FieldLogFileReader reader) { FieldLogStackFrame frame = new FieldLogStackFrame(); frame.Module = reader.ReadString(); if (reader.FormatVersion >= 2) { frame.Token = reader.ReadInt32(); frame.ILOffset = reader.ReadInt32(); } frame.TypeName = reader.ReadString(); frame.MethodName = reader.ReadString(); frame.MethodSignature = reader.ReadString(); frame.FileName = reader.ReadString(); frame.Line = reader.ReadInt32(); frame.Column = reader.ReadInt32(); return frame; }