public static List <string> GetStackTrace(int skip = 2) { var result = new List <string>(); var stack = new System.Diagnostics.StackTrace(true).ToString(); var trace = new List <string>(stack.Split('\n')); trace.RemoveRange(0, skip); trace.Reverse(); bool found = false; foreach (string e in trace) { if (!found && e.Contains("Main")) { found = true; } if (found) { result.Add(e.Replace('\n', ' ').Replace("\r", "").Replace('\t', ' ')); } } result.Reverse(); return(result); }
public static string GetStackTrace(string indent) { #if SILVERLIGHT var trace = new System.Diagnostics.StackTrace().ToString(); #elif PORTABLE var trace = new StackTrace().ToString(); #else var skipCount = new System.Diagnostics.StackTrace().GetFrames().TakeWhile(frame => frame.GetMethod().DeclaringType.Assembly == typeof(DebugView).Assembly).Count(); var trace = new System.Diagnostics.StackTrace(skipCount, true).ToString(); #endif return("\n".Join(trace .Split('\n') .Select(p => indent + p.Trim()))); }
private RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception) { var lines = new List<RaygunErrorStackTraceLineMessage>(); #if !WINRT var stackTrace = new StackTrace(exception, true); var frames = stackTrace.GetFrames(); if (frames == null || frames.Length == 0) { var line = new RaygunErrorStackTraceLineMessage { FileName = "none", LineNumber = 0 }; lines.Add(line); return lines.ToArray(); } foreach (StackFrame frame in frames) { MethodBase method = frame.GetMethod(); if (method != null) { int lineNumber = frame.GetFileLineNumber(); if (lineNumber == 0) { lineNumber = frame.GetILOffset(); } var methodName = GenerateMethodName(method); string file = frame.GetFileName(); string className = method.ReflectedType != null ? method.ReflectedType.FullName : "(unknown)"; var line = new RaygunErrorStackTraceLineMessage { FileName = file, LineNumber = lineNumber, MethodName = methodName, ClassName = className }; lines.Add(line); } } #else string[] delim = { "\r\n" }; string stackTrace = exception.Data["Message"] as string; if (stackTrace != null) { var frames = stackTrace.Split(delim, StringSplitOptions.RemoveEmptyEntries); foreach (string line in frames) { lines.Add(new RaygunErrorStackTraceLineMessage() { ClassName = line }); } } #endif return lines.ToArray(); }
public static string GetStackTrace(string indent) { #if SILVERLIGHT var trace = new System.Diagnostics.StackTrace().ToString(); #elif PORTABLE var trace = new StackTrace().ToString(); #else var skipCount = new System.Diagnostics.StackTrace().GetFrames().TakeWhile(frame => frame.GetMethod().DeclaringType.Assembly == typeof(DebugView).Assembly).Count(); var trace = new System.Diagnostics.StackTrace(skipCount, true).ToString(); #endif return "\n".Join(trace .Split('\n') .Select(p => indent + p.Trim())); }