Share via


HOW TO:寫入記錄訊息

更新:2007 年 11 月

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

如需記錄例外狀況 (Exception) 資訊,請使用 My.Application.Log.WriteException 方法。請參閱 HOW TO:在 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 中使用應用程式記錄檔

請參閱

工作

HOW TO:在 Visual Basic 中記錄例外狀況

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

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

逐步解說:篩選 My.Application.Log 輸出

概念

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

參考

My.Application.Log 物件

My.Log 物件

WriteEntry 方法 (My.Application.Log 和 My.Log)

WriteException 方法 (My.Application.Log 和 My.Log)