public static StackTraceInfo GetStackTrace() { StackTrace st = new StackTrace(true); StackTraceInfo info = new StackTraceInfo(); info.MyStackTraceList = new List <StackTraceInfoItem>(); info.SugarStackTraceList = new List <StackTraceInfoItem>(); for (int i = 0; i < st.FrameCount; i++) { var frame = st.GetFrame(i); if (frame.GetMethod().Module.Name.ToLower() != "sqlsugar.dll" && frame.GetMethod().Name.First() != '<') { info.MyStackTraceList.Add(new StackTraceInfoItem() { FileName = frame.GetFileName(), MethodName = frame.GetMethod().Name, Line = frame.GetFileLineNumber() }); } else { info.SugarStackTraceList.Add(new StackTraceInfoItem() { FileName = frame.GetFileName(), MethodName = frame.GetMethod().Name, Line = frame.GetFileLineNumber() }); } } return(info); }
/// <summary> /// Writes an exception into one or more log entries, storing them in entries with a given prefix /// </summary> /// <param name="source">Log source</param> /// <param name="ex">Exception</param> /// <param name="entries">Log entry list</param> /// <param name="prefix">Entry string prefix</param> public static void ToLogEntries( Source source, Exception ex, IList< Entry > entries, string prefix ) { if ( ex == null ) { return; } StackTraceInfo info = new StackTraceInfo( ex.StackTrace ); Entry baseEntry = new Entry( source, prefix + ex.Message ); if ( info.HasMatch ) { baseEntry.Locate( info.File, int.Parse( info.Line ), 1, info.Method ); info.NextMatch( ); } entries.Add( baseEntry ); while ( info.HasMatch ) { entries.Add( new Entry( source, prefix + "(call stack)" ).Locate( info.File, int.Parse( info.Line ), 1, info.Method ) ); info.NextMatch( ); } ToLogEntries( source, ex.InnerException, entries, prefix + "\t" ); }
private static string TrySymbolicateLine(string line) { Match match = s_regex.Match(line); if (!match.Success) { return(line); } StackTraceInfo stInfo = new StackTraceInfo() { Type = match.Groups["type"].Value, Method = match.Groups["method"].Value, Param = match.Groups["params"].Value, Assembly = match.Groups["filename"].Value, Token = match.Groups["token"].Value, Offset = match.Groups["offset"].Value }; if (stInfo.Assembly.Contains(".ni.dll")) { stInfo.Filename = stInfo.Assembly.Replace(".ni.dll", ""); } else { stInfo.Filename = stInfo.Assembly.Replace(".dll", ""); } stInfo.Pdb = stInfo.Filename + ".pdb"; return(GetLineFromMetadata(TryGetMetadataReader(stInfo.Filename), line, stInfo)); }
public StackTraceViewModel(StackTraceInfo stackTrace) { this.stackTrace = stackTrace; frames = stackTrace.Addresses.Select(x => new StackFrame(x)).ToList(); }
/// <summary> /// Converts an exception to a string, with a given number of tabs preceeding the output /// </summary> public static string ToString( Exception e, int tabs ) { if ( e == null ) { return ""; } StringBuilder tabStringBuilder = new StringBuilder( tabs, tabs + 1 ); // Insert tabs for ( int tabCount = 0; tabCount < tabs; ++tabCount ) { tabStringBuilder.Append( '\t' ); } string tabString = tabStringBuilder.ToString( ); StringBuilder builder = new StringBuilder( 256 ); // Keep the first part of the original exception string format: "type : message" builder.Append( tabString ); builder.Append( e.GetType( ).Name ); builder.Append( " : " ); builder.Append( e.Message ); builder.Append( kNewLine ); // GRRR there's no representation of the stack trace apart from the string :( // Tear it apart using regular expressions and rebuild // TODO: If no matches are found, then just write the StackTrace to the builder for ( StackTraceInfo info = new StackTraceInfo( e.StackTrace ); info.HasMatch; info.NextMatch( ) ) { builder.AppendFormat( tabString ); builder.AppendFormat( "{0}({1}): {2}", info.File, info.Line, info.Method ); builder.Append( kNewLine ); } return builder + ToString( e.InnerException, tabs + 1 ); }