How to: Write Log Messages
You can use the My.Application.Log and My.Log objects to log information about your application. This example shows how to use the My.Application.Log.WriteEntry method to log tracing information.
For logging exception information, use the My.Application.Log.WriteException method; see How to: Log Exceptions in Visual Basic.
Example
This example uses the My.Application.Log.WriteEntry method to write out the trace information.
Public Sub TracingTest(ByVal fileName As String)
My.Application.Log.WriteEntry( _
"Entering TracingTest with argument " & _
fileName & ".")
' Code to trace goes here.
My.Application.Log.WriteEntry( _
"Exiting TracingTest with argument " & _
fileName & ".")
End Sub
Security
Make sure the data you write to the log does not include sensitive information such as user passwords. For more information, see Working with Application Logs in Visual Basic.
See Also
Tasks
How to: Log Exceptions in Visual Basic
Walkthrough: Determining Where My.Application.Log Writes Information
Walkthrough: Changing Where My.Application.Log Writes Information
Walkthrough: Filtering My.Application.Log Output
Concepts
Working with Application Logs in Visual Basic