private static string[] BuildStackTrace(Exception exception) { var lines = new List <StackTraceLineMessage>(); var stackTrace = new StackTrace(exception, true); var frames = stackTrace.GetFrames(); if (frames == null || frames.Length == 0) { var line = new StackTraceLineMessage { FileName = "none", LineNumber = 0 }; lines.Add(line); return(lines.Select(x => x.ToString()).ToArray()); } foreach (var frame in frames) { var method = frame.GetMethod(); if (method == null) { continue; } var lineNumber = frame.GetFileLineNumber(); if (lineNumber == 0) { lineNumber = frame.GetILOffset(); } var methodName = GenerateMethodName(method); var file = frame.GetFileName(); var className = method.ReflectedType != null ? method.ReflectedType.FullName : "(unknown)"; var line = new StackTraceLineMessage { FileName = file, LineNumber = lineNumber, MethodName = methodName, ClassName = className }; lines.Add(line); } return(lines.Select(x => x.ToString()).ToArray()); }
private static string[] BuildStackTrace(Exception exception) { var lines = new List<StackTraceLineMessage>(); var stackTrace = new StackTrace(exception, true); var frames = stackTrace.GetFrames(); if (frames == null || frames.Length == 0) { var line = new StackTraceLineMessage { FileName = "none", LineNumber = 0 }; lines.Add(line); return lines.Select(x => x.ToString()).ToArray(); } foreach (var frame in frames) { var method = frame.GetMethod(); if (method == null) continue; var lineNumber = frame.GetFileLineNumber(); if (lineNumber == 0) { lineNumber = frame.GetILOffset(); } var methodName = GenerateMethodName(method); var file = frame.GetFileName(); var className = method.ReflectedType != null ? method.ReflectedType.FullName : "(unknown)"; var line = new StackTraceLineMessage { FileName = file, LineNumber = lineNumber, MethodName = methodName, ClassName = className }; lines.Add(line); } return lines.Select(x => x.ToString()).ToArray(); }