共用方式為


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

更新:2007 年 11 月

將訊息寫入應用程式的記錄檔接聽程式。

' Usage
My.Application.Log.WriteEntry(message)
My.Application.Log.WriteEntry(message ,severity)
My.Application.Log.WriteEntry(message ,severity ,id)
' Web usage
My.Log.WriteEntry(message)
My.Log.WriteEntry(message ,severity)
My.Log.WriteEntry(message ,severity ,id)
' Declaration
Public Sub WriteEntry( _
   ByVal message As String _
)
' -or-
Public Sub WriteEntry( _
   ByVal message As String, _
   ByVal severity As System.Diagnostics.TraceEventType _
)
' -or-
Public Sub WriteEntry( _
   ByVal message As String, _
   ByVal severity As System.Diagnostics.TraceEventType, _
   ByVal id As Integer _
)

參數

  • message
    必要項。要記錄的訊息。如果 message 是 Nothing,則會使用空白字串。

  • severity
    訊息的型別。預設值為 TraceEventType.Information。

  • id
    訊息識別項,一般是用於相互關聯。預設會與 entryType 產生關聯 (如表格中所述)。

例外狀況

下列情況會造成例外狀況:

備註

WriteEntry 方法會將訊息寫入至應用程式的事件記錄檔接聽程式中。

在用戶端應用程式中,透過 My.Application.Log 物件可以使用 Log 物件。在 Web 應用程式中,透過 My.Log 物件可以使用 Log 物件。

若要瞭解接收 WriteEntry 方法之訊息的記錄檔接聽程式,請參閱逐步解說:判斷 My.Application.Log 寫入資訊的位置。您可以變更預設記錄檔接聽程式。如需詳細資訊,請參閱在 Visual Basic 中使用應用程式記錄檔

若為未使用 id 引數的多載,則是由下表定義寫入至記錄檔中的 id。

severity

預設 id

Information

0

Warning

1

Error

2

Critical

3

Start

4

Stop

5

Suspend

6

Resume

7

Verbose

8

Transfer

9

工作

下表列出包含 WriteEntry 方法的工作範例。

若要

請參閱

將事件資訊寫入應用程式的記錄檔接聽程式

HOW TO:寫入記錄訊息

判斷 Log 寫入資訊的位置

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

範例

這個範例顯示如何使用 My.Application.Log.WriteEntry 方法,記錄追蹤資訊。如需詳細資訊,請參閱 HOW TO:寫入記錄訊息

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

這個程式碼範例只能在用戶端應用程式內執行。若為 Web 應用程式,請將 My.Application.Log.WriteEntry 變更成 My.Log.WriteEntry。

需求

命名空間 (Namespace)︰Microsoft.VisualBasic.Logging

類別︰Log

組件 (Assembly):Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

依專案類型的可用性

專案類型

是否可用

Windows 應用程式

類別庫

主控台應用程式

Windows 控制項程式庫

Web 控制項程式庫

Windows 服務

網站

使用權限

下列使用權限可能為必要:

使用權限

描述

FileIOPermission

控制存取檔案和資料夾的功能。關聯的列舉型別:Unrestricted

如需詳細資訊,請參閱程式碼存取安全性要求使用權限

請參閱

工作

HOW TO:寫入記錄訊息

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

概念

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

參考

My.Application.Log 物件

My.Log 物件

System.Diagnostics.TraceEventType

Log.WriteEntry