如何:写入日志消息

更新:2007 年 11 月

您可以使用 My.Application.Log 和 My.Log 对象记录应用程序的有关信息。此示例演示如何使用 My.Application.Log.WriteEntry 方法来记录跟踪信息。

若要记录异常信息,请使用 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

安全性

确保写入日志的数据不包含敏感信息,如用户密码。有关更多信息,请参见使用 Application 日志 (Visual Basic)

请参见

任务

如何:在 Visual Basic 中记录异常

演练:确定 My.Application.Log 写入信息的位置

演练:更改 My.Application.Log 写入信息的位置

演练:筛选 My.Application.Log 输出

概念

使用 Application 日志 (Visual Basic)

参考

My.Application.Log 对象

My.Log 对象

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

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