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