共用方式為


如何:寫入記錄訊息 (Visual Basic)

您可以使用 My.Application.Log 和 My.Log 物件,記錄應用程式的相關資訊。 這個範例顯示如何使用 My.Application.Log.WriteEntry 方法,記錄追蹤資訊。

如需記錄例外狀況 (Exception) 資訊,請使用 My.Application.Log.WriteException 方法。請參閱 如何:在 Visual Basic 中記錄例外狀況

範例

這個範例會使用 My.Application.Log.WriteEntry 方法,將追蹤資訊寫出。

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

安全性

確定您寫入記錄檔的資料不包含機密資訊,例如使用者密碼。 如需詳細資訊,請參閱在 Visual Basic 中使用應用程式記錄檔

請參閱

工作

如何:在 Visual Basic 中記錄例外狀況

逐步解說:判斷 My.Application.Log 寫入資訊的位置 (Visual Basic)

逐步解說:變更 My.Application.Log 寫入資訊的位置 (Visual Basic)

逐步解說:篩選 My.Application.Log 輸出 (Visual Basic)

參考

Log

WriteEntry

WriteException

概念

在 Visual Basic 中使用應用程式記錄檔