本文整理汇总了C#中System.Diagnostics.StackTrace.Select方法的典型用法代码示例。如果您正苦于以下问题:C# StackTrace.Select方法的具体用法?C# StackTrace.Select怎么用?C# StackTrace.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.StackTrace
的用法示例。
在下文中一共展示了StackTrace.Select方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThrowWhenNoAppStartupsFixtureRuns
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();
}
}
示例2: RollbarTrace
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);
}
示例3: WriteLine
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);
}
示例4: GetCurrentFeatureFile
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;
}
}
示例5: SimpleExceptionDetail
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
});
}
示例6: GetSocketPurpose
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()))}");
}
示例7: FromParameters
/// <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
}
};
}