Programmatically get C# Stack Trace
30,309
Solution 1
Environment.StackTrace or System.Diagnostics.StackTrace if you need a more convienient (i.e. not string) representation
Solution 2
Yes ...
StackTrace stackTrace = new StackTrace(); // get call stack
StackFrame[] stackFrames = stackTrace.GetFrames()
Solution 3
string stackTrace = Environment.StackTrace;
Author by
Armen Tsirunyan
Updated on July 09, 2022Comments
-
Armen Tsirunyan almost 2 years
Possible Duplicate:
How to print the current Stack Trace in .NET without any exception?When an exception is thrown, its text contains the stack trace. Can I somehow obtain the stack trace text(including file and line) without exceptions?
public void f() { //blah string stacktrace = ???; //blah }