Find the Previous Method Called

To determine what the previous method called was prior to your current location in the code, try the following:

string previousMethod = new System.Diagnostics.StackFrame(1, false).GetMethod().Name;

This is a great quick way to determine the previous method for logging purposes in an obtuse code base.

This entry was posted in C#. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *