P
pukya78
Hi,
I am trying to get the current file and the line number which is
getting executed. I used:
MessageBox.Show(New StackTrace(New
StackFrame(True)).GetFrame(0).GetFileLineNumber) which gives me the
line number.
Later on, I was trying to write a generalized routine, so that I can
log the file name and the method.
<code>
Public Function MeAndMyCaller As String
Dim CurrentStack As New System.Diagnostics.StackTrace
Dim Myself As String = CurrentStack.GetFrame(0).GetMethod.Name
Dim MyCaller As String = CurrentStack.GetFrame(1).GetMethod.Name
Dim cur_file As String = CurrentStack.GetFrame(1).GetFileName
Dim line_num As Integer = CurrentStack.GetFrame(1).GetFileLineNumber
Return "In " & Myself & vbCrLf & "Called by " & MyCaller
End Function
</code>
Here, I get MyCaller correctly, but cur_file is not getting returned. I
get a Null exception. line_num is returned as 0, all the time.
What am I doing wrong? Any suggestions/ideas?
Regards,
P
I am trying to get the current file and the line number which is
getting executed. I used:
MessageBox.Show(New StackTrace(New
StackFrame(True)).GetFrame(0).GetFileLineNumber) which gives me the
line number.
Later on, I was trying to write a generalized routine, so that I can
log the file name and the method.
<code>
Public Function MeAndMyCaller As String
Dim CurrentStack As New System.Diagnostics.StackTrace
Dim Myself As String = CurrentStack.GetFrame(0).GetMethod.Name
Dim MyCaller As String = CurrentStack.GetFrame(1).GetMethod.Name
Dim cur_file As String = CurrentStack.GetFrame(1).GetFileName
Dim line_num As Integer = CurrentStack.GetFrame(1).GetFileLineNumber
Return "In " & Myself & vbCrLf & "Called by " & MyCaller
End Function
</code>
Here, I get MyCaller correctly, but cur_file is not getting returned. I
get a Null exception. line_num is returned as 0, all the time.
What am I doing wrong? Any suggestions/ideas?
Regards,
P