AspLog 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供一個屬性與方法,用於將事件與異常資訊寫入應用程式的日誌監聽器。
public ref class AspLog : Microsoft::VisualBasic::Logging::Log
public class AspLog : Microsoft.VisualBasic.Logging.Log
type AspLog = class
inherit Log
Public Class AspLog
Inherits Log
- 繼承
範例
此範例展示了如何使用此 My.Application.Log.WriteEntry 方法記錄追蹤資訊。 欲了解更多資訊,請參閱 「如何撰寫日誌訊息」。
Private Sub GetOpenFormTitles()
Dim formTitles As New Collection
Try
For Each f As Form In My.Application.OpenForms
' Use a thread-safe method to get all form titles.
formTitles.Add(GetFormTitle(f))
Next
Catch ex As Exception
formTitles.Add("Error: " & ex.Message)
End Try
Form1.ListBox1.DataSource = formTitles
End Sub
Private Delegate Function GetFormTitleDelegate(f As Form) As String
Private Function GetFormTitle(f As Form) As String
' Check if the form can be accessed from the current thread.
If Not f.InvokeRequired Then
' Access the form directly.
Return f.Text
Else
' Marshal to the thread that owns the form.
Dim del As GetFormTitleDelegate = AddressOf GetFormTitle
Dim param As Object() = {f}
Dim result As System.IAsyncResult = f.BeginInvoke(del, param)
' Give the form's thread a chance process function.
System.Threading.Thread.Sleep(10)
' Check the result.
If result.IsCompleted Then
' Get the function's return value.
Return "Different thread: " & f.EndInvoke(result).ToString
Else
Return "Unresponsive thread"
End If
End If
End Function
備註
My.Application.Log 物件提供了一個直接的入口,方便存取 .NET Framework 的日誌服務。
WriteEntry和 WriteException 方法會將訊息寫入應用程式的日誌監聽器。 監聽器可由應用程式的設定檔設定。 欲了解更多資訊,請參閱 攻略:變更 My.Application.Log 在哪裡寫入資訊 及 處理應用程式日誌。
此 My.Application.Log 物件僅提供給用戶端應用程式使用。 對於網頁應用程式,請使用 My.Log. 如需詳細資訊,請參閱Microsoft.VisualBasic.Logging.Log。
下表列出涉及該 My.Application.Log 物件的任務範例。
| 至 | 看! |
|---|---|
| 將事件資訊寫入應用程式的日誌監聽器 | 如何:寫入記錄訊息 |
| 將異常資訊寫入應用程式的日誌監聽器 | 如何:記錄例外狀況 |
判斷資訊寫入位置My.Application.Log |
操作指南:判斷 My.Application.Log 寫入資訊的位置 |
建構函式
| 名稱 | Description |
|---|---|
| AspLog() |
初始化 AspLog 類別的新執行個體。 |
| AspLog(String) |
初始化 AspLog 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| DefaultFileLogWriter |
取得該 |
| TraceSource |
能接觸 TraceSource 到該物件底下的 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的 物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| InitializeWithDefaultsSinceNoConfigExists() |
建立一個新 FileLogTraceListener 檔案並加入 Listeners 收藏。 |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
| WriteEntry(String, TraceEventType, Int32) |
會寫訊息給應用程式的日誌監聽器。 (繼承來源 Log) |
| WriteEntry(String, TraceEventType) |
會寫訊息給應用程式的日誌監聽器。 (繼承來源 Log) |
| WriteEntry(String) |
會寫訊息給應用程式的日誌監聽器。 (繼承來源 Log) |
| WriteException(Exception, TraceEventType, String, Int32) |
將例外資訊寫入應用程式的日誌監聽器。 (繼承來源 Log) |
| WriteException(Exception, TraceEventType, String) |
將例外資訊寫入應用程式的日誌監聽器。 (繼承來源 Log) |
| WriteException(Exception) |
將例外資訊寫入應用程式的日誌監聽器。 (繼承來源 Log) |