There might be times when you need the name of the method when logging Exceptions etc. The code below uses reflection and will also add the class name:
1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
2 Dim dir = String.Format(“{0}.{1}”, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, System.Reflection.MethodBase.GetCurrentMethod().Name)
The output would look like this:
>? dir
"Form1.Form1_Load"
If you also want the name of the application, use DeclaringType.FullName instead of just .Name.
Tip Submitted By: David McCarter
Discover more from dotNetTips.com
Subscribe to get the latest posts sent to your email.
