private static void ThrowWhenNoAppStartupsFixtureRuns() { var frames = new StackTrace().GetFrames(); if (frames != null && frames.Select(f => f.GetMethod().DeclaringType).Any(t => t == typeof(NoAppStartupsFixture))) { throw new Exception(); } }
public RollbarTrace(Exception exception) { if (exception == null) { throw new ArgumentNullException("exception"); } var frames = new StackTrace(exception, true).GetFrames() ?? new StackFrame[0]; Frames = frames.Select(frame => new RollbarFrame(frame)).ToArray(); Exception = new RollbarException(exception); }
public static void WriteLine(LogLevel level, string format, params object[] args) { var message = string.Format(format, args); if (level < Verbosity) return; var stackFrames = new StackTrace().GetFrames(); if (stackFrames == null) return; var types = stackFrames.Select(frame => frame.GetMethod().DeclaringType); var type = types.First(t => t != typeof(Log) && t != null); Output [level](level, type.Name + ": " + message); }
private static string GetCurrentFeatureFile() { try { var frames = new StackTrace(true).GetFrames(); if (frames == null) return null; return frames.Select(f => f.GetFileName()).FirstOrDefault(fn => fn != null && fn.EndsWith(".feature")); } catch (Exception ex) { Debug.WriteLine(ex, "GetCurrentPositionText"); return null; } }
public SimpleExceptionDetail(System.Exception e, bool isIncludeStack = true) : this() { Message = e.Message; Type = e.GetType().FullName; if (!isIncludeStack) return; var frames = new StackTrace(e, true).GetFrames(); if (frames == null || !frames.Any()) return; StacktraceDetails = frames.Select(r => new SimpleStacktraceDetail { File = r.GetFileName(), LineNumber = r.GetFileLineNumber(), Method = r.GetMethod().Name }); }
private SocketPurpose GetSocketPurpose() { var stackFrames = new StackTrace(1).GetFrames(); if (stackFrames .FirstOrDefault(sf => sf.GetMethod().Name == CreateClusterMonitorSendingSocketMethod) != null) { return SocketPurpose.ClusterMonitorSendingSocket; } if (stackFrames .FirstOrDefault(sf => sf.GetMethod().Name == CreateClusterMonitorSubscriptionSocketMethod) != null) { return SocketPurpose.ClusterMonitorSubscriptionSocket; } if (stackFrames .FirstOrDefault(sf => sf.GetMethod().Name == CreateRouterCommunicationSocketMethod) != null) { return SocketPurpose.RouterCommunicationSocket; } throw new Exception($"Socket creation method is unexpected: {string.Join(" @ ", stackFrames.Select(sf => sf.ToString()))}"); }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="message"></param> /// <param name="objects"></param> /// <param name="methodName"></param> /// <param name="sourceFilePath"></param> /// <param name="sourceLineNumber"></param> /// <returns></returns> public static LogInfo FromParameters(LogType type, string message, object[] objects, string methodName, string sourceFilePath, int sourceLineNumber) { var stackFrames = new StackTrace(true).GetFrames(); return new LogInfo { Date = DateTime.Now, LogType = type, Message = objects == null ? message : string.Format(message, objects), Objects = objects, StackTrace = stackFrames == null ? new string[0] : stackFrames.Select(s => s.ToString()).ToArray(), CallerInfo = new CallerInfo { LineNumber = sourceLineNumber, MethodName = methodName, SourceFilePath = sourceFilePath } }; }