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 產生關聯 (如表格中所述)。
例外狀況
下列情況會造成例外狀況:
例外狀況或訊息型別是 Nothing (ArgumentNullException)。
訊息型別不是其中一個 TraceEventType 列舉值 (InvalidEnumArgumentException)。
具有部分信任的程式碼會呼叫該方法,但寫入至需要完全信任 (SecurityException) 的事件記錄檔接聽程式中。
備註
WriteEntry 方法會將訊息寫入至應用程式的事件記錄檔接聽程式中。
在用戶端應用程式中,透過 My.Application.Log 物件可以使用 Log 物件。在 Web 應用程式中,透過 My.Log 物件可以使用 Log 物件。
若要瞭解接收 WriteEntry 方法之訊息的記錄檔接聽程式,請參閱逐步解說:判斷 My.Application.Log 寫入資訊的位置。您可以變更預設記錄檔接聽程式。如需詳細資訊,請參閱在 Visual Basic 中使用應用程式記錄檔。
若為未使用 id 引數的多載,則是由下表定義寫入至記錄檔中的 id。
severity |
預設 id |
---|---|
0 |
|
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
工作
下表列出包含 WriteEntry 方法的工作範例。
若要 |
請參閱 |
---|---|
將事件資訊寫入應用程式的記錄檔接聽程式 |
|
判斷 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 服務 |
是 |
網站 |
是 |
使用權限
下列使用權限可能為必要:
使用權限 |
描述 |
---|---|
控制存取檔案和資料夾的功能。關聯的列舉型別:Unrestricted。 |
請參閱
工作
逐步解說:判斷 My.Application.Log 寫入資訊的位置