using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace ZeroLevel.Services.Diagnostics { /// /// Performs read of stack trace /// public static class StackTraceReader { /// /// Read current stack trace /// /// Result - enumerable of tuples as 'Type':'MethodName' public static Tuple[] ReadFrames() { var result = new List>(); var stackTrace = new StackTrace(); foreach (var frame in stackTrace.GetFrames() ?? Enumerable.Empty()) { var method = frame.GetMethod(); if (method != null && method.DeclaringType != null) { var type = method.DeclaringType.Name; if (false == type.Equals("StackTraceReader", StringComparison.Ordinal)) { result.Add(new Tuple(type, method.Name)); } } } return result.ToArray(); } } }