How to get the name of the calling method in C# and VB.NET

To get the name of the calling method in C# and VB.NET you can use the snippet below.

Sample C#

public static string GetCallingMethodName()
{
	var stackTrace = new StackTrace();
	return stackTrace.GetFrame(1).GetMethod().Name;
}

Sample VB.NET

Public Shared Function GetCallingMethodName() As String
	Dim stackTrace = New StackTrace()
	Return stackTrace.GetFrame(1).GetMethod().Name
End Function

How to get the current Stack Trace without having a exception?

To print the current Stack Trace without having a exception you can use the StackTrace class located in System.Diagnostics Namespace

Sample C#

System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();

Sample VB.NET

Dim stackTrace As New System.Diagnostics.StackTrace()

for more informations take a look at the MSDN: StackTrace Class, System.Diagnostics Namespace