Friday, July 15, 2011

Trace the stack

There are two ways to get current stack trace:

1. Using System.Diagnostics.StackTrace:
var stackTrace = new StackTrace(true);
foreach (var r in stackTrace.GetFrames())
{
       Console.WriteLine("Filename: {0} Method: {1} Line: {2} Column: {3}  ",
           r.GetFileName(),r.GetMethod(), r.GetFileLineNumber(),
           r.GetFileColumnNumber() );
}

2. Using System.Environment:

Console.WriteLine(Environment.StackTrace);

No comments:

Post a Comment