Line numbers and method name for EventLog

  • Thread starter Thread starter Claus Rathje
  • Start date Start date
C

Claus Rathje

Where do I find line numbers and source file information that I can
print to for example the EventLog, making it easier to debug errors?


Claus Rathje
TDC Services A/S
 
Does this help

Imports System
Imports System.IO
Imports System.Diagnostics

Class Class1
Public Sub myMethod()
Throw New Exception("exception thrown on purpose")
End Sub

End Class
Module Module1

Sub Main()

Dim mClass As New Class1
Try
mClass.myMethod()
Catch e As Exception
' Display file and line information, if available.
Dim sf As New StackFrame(True)
Dim st As New StackTrace(sf)

Console.WriteLine(" StackTrace: " & st.ToString())
Console.WriteLine(" Line Number : " &
st.GetFrame(0).GetFileLineNumber())
Console.WriteLine("-------------------------------------------------")
Console.WriteLine(e.StackTrace)
Console.WriteLine("-------------------------------------------------")
End Try

End Sub

End Module
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top