Display the call stack method names in C#

using System.Diagnostics;
public static void Main()
  //obtain call stack
  StackTrace stackTrace = new StackTrace();
  // obtain method calls (frames)
  StackFrame[] stackFrames = stackTrace.GetFrames(); 
  // display method names
  foreach (StackFrame stackFrame in stackFrames)
    Console.WriteLine(stackFrame.GetMethod().Name);   // output method name

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.