(EDIT: Removed unnecessary use of StackTrace
itself - which would be useful if you wanted to print out more info than just one frame.)
You can use the StackFrame
class, but it's pretty expensive (IIRC) and may be slightly incorrect due to inlining.
EDIT: Something like this: (the NoInlining is to make sure it behaves properly...)
Imports System.Diagnostics
Imports System.Runtime.CompilerServices
Public Class Test
Shared Sub Main()
Something()
End Sub
<MethodImpl(MethodImplOptions.NoInlining)> _
Shared Sub Something()
Functions.LogInfo("some text")
End Sub
End Class
Public Class Functions
<MethodImpl(MethodImplOptions.NoInlining)> _
Public Shared Sub LogInfo (ByVal entry as String)
Dim frame as StackFrame = new StackFrame(1, False)
Console.WriteLine("{0}: {1}", _
frame.GetMethod.Name, _
entry)
End Sub
End Class