Log.WriteEntry Metode

Definisi

Menulis pesan ke pendengar log aplikasi.

Overload

Nama Deskripsi
WriteEntry(String)

Menulis pesan ke pendengar log aplikasi.

WriteEntry(String, TraceEventType)

Menulis pesan ke pendengar log aplikasi.

WriteEntry(String, TraceEventType, Int32)

Menulis pesan ke pendengar log aplikasi.

WriteEntry(String)

Sumber:
Log.vb
Sumber:
Log.vb
Sumber:
Log.vb
Sumber:
Log.vb
Sumber:
Log.vb

Menulis pesan ke pendengar log aplikasi.

public:
 void WriteEntry(System::String ^ message);
public void WriteEntry(string message);
member this.WriteEntry : string -> unit
Public Sub WriteEntry (message As String)

Parameter

message
String

Required. Pesan yang akan dicatat. Jika message adalah Nothing, string kosong digunakan.

Pengecualian

Kode dengan kepercayaan parsial memanggil metode , tetapi menulis ke pendengar log peristiwa yang memerlukan kepercayaan penuh.

Contoh

Contoh ini menunjukkan cara menggunakan My.Application.Log.WriteEntry metode untuk mencatat informasi pelacakan. Untuk informasi selengkapnya, lihat Cara: Menulis Pesan Log.

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

Contoh kode ini hanya dapat berjalan dalam aplikasi klien. Ubah My.Application.Log.WriteEntry ke My.Log.WriteEntry untuk aplikasi Web.

Keterangan

Metode ini WriteEntry menulis pesan ke pendengar log peristiwa aplikasi.

Dalam aplikasi klien, Log objek tersedia melalui My.Application.Log objek . Dalam aplikasi Web, Log objek tersedia melalui My.Log objek .

Untuk mempelajari pendengar log mana yang menerima WriteEntry pesan metode, lihat Panduan: Menentukan Di Mana Informasi Penulisan My.Application.Log. Anda dapat mengubah pendengar log default. Untuk informasi selengkapnya, lihat Bekerja dengan Log Aplikasi.

Untuk kelebihan beban yang tidak mengambil id argumen, id yang ditulis ke log ditentukan oleh tabel berikut.

severity id default
Information 0
Warning 1
Error 2
Critical 3
Start 4
Stop 5
Suspend 6
Resume 7
Verbose 8
Transfer 9

Tabel berikut ini mencantumkan contoh tugas yang melibatkan WriteEntry metode .

Untuk Lihat
Menulis informasi peristiwa ke pendengar log aplikasi Cara: Menulis Pesan Log
Menentukan tempat Log menulis informasi Panduan: Menentukan Di mana My.Application.Log Menulis Informasi

Ketersediaan menurut Jenis Proyek

Jenis proyek Available
Aplikasi Windows Yes
Pustaka Kelas Yes
Aplikasi Konsol Yes
Pustaka Kontrol Windows Yes
Perpustakaan Kontrol Situs Web Tidak
Layanan Windows Yes
Situs Web Yes

Lihat juga

Berlaku untuk

WriteEntry(String, TraceEventType)

Sumber:
Log.vb
Sumber:
Log.vb
Sumber:
Log.vb
Sumber:
Log.vb
Sumber:
Log.vb

Menulis pesan ke pendengar log aplikasi.

public:
 void WriteEntry(System::String ^ message, System::Diagnostics::TraceEventType severity);
public void WriteEntry(string message, System.Diagnostics.TraceEventType severity);
member this.WriteEntry : string * System.Diagnostics.TraceEventType -> unit
Public Sub WriteEntry (message As String, severity As TraceEventType)

Parameter

message
String

Required. Pesan yang akan dicatat. Jika message adalah Nothing, string kosong digunakan.

severity
TraceEventType

Jenis pesan. Secara bawaan, TraceEventType.Information.

Pengecualian

Jenis pesan bukan salah TraceEventType satu nilai enumerasi.

Kode dengan kepercayaan parsial memanggil metode , tetapi menulis ke pendengar log peristiwa yang memerlukan kepercayaan penuh.

Contoh

Contoh ini menunjukkan cara menggunakan My.Application.Log.WriteEntry metode untuk mencatat informasi pelacakan. Untuk informasi selengkapnya, lihat Cara: Menulis Pesan Log.

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

Contoh kode ini hanya dapat berjalan dalam aplikasi klien. Ubah My.Application.Log.WriteEntry ke My.Log.WriteEntry untuk aplikasi Web.

Keterangan

Metode ini WriteEntry menulis pesan ke pendengar log peristiwa aplikasi.

Dalam aplikasi klien, Log objek tersedia melalui My.Application.Log objek . Dalam aplikasi Web, Log objek tersedia melalui My.Log objek .

Untuk mempelajari pendengar log mana yang menerima WriteEntry pesan metode, lihat Panduan: Menentukan Di Mana Informasi Penulisan My.Application.Log. Anda dapat mengubah pendengar log default. Untuk informasi selengkapnya, lihat Bekerja dengan Log Aplikasi.

Untuk kelebihan beban yang tidak mengambil id argumen, id yang ditulis ke log ditentukan oleh tabel berikut.

severity id default
Information 0
Warning 1
Error 2
Critical 3
Start 4
Stop 5
Suspend 6
Resume 7
Verbose 8
Transfer 9

Tabel berikut ini mencantumkan contoh tugas yang melibatkan WriteEntry metode .

Untuk Lihat
Menulis informasi peristiwa ke pendengar log aplikasi Cara: Menulis Pesan Log
Menentukan tempat Log menulis informasi Panduan: Menentukan Di mana My.Application.Log Menulis Informasi

Ketersediaan menurut Jenis Proyek

Jenis proyek Available
Aplikasi Windows Yes
Pustaka Kelas Yes
Aplikasi Konsol Yes
Pustaka Kontrol Windows Yes
Perpustakaan Kontrol Situs Web Tidak
Layanan Windows Yes
Situs Web Yes

Lihat juga

Berlaku untuk

WriteEntry(String, TraceEventType, Int32)

Sumber:
Log.vb
Sumber:
Log.vb
Sumber:
Log.vb
Sumber:
Log.vb
Sumber:
Log.vb

Menulis pesan ke pendengar log aplikasi.

public:
 void WriteEntry(System::String ^ message, System::Diagnostics::TraceEventType severity, int id);
public void WriteEntry(string message, System.Diagnostics.TraceEventType severity, int id);
member this.WriteEntry : string * System.Diagnostics.TraceEventType * int -> unit
Public Sub WriteEntry (message As String, severity As TraceEventType, id As Integer)

Parameter

message
String

Required. Pesan yang akan dicatat. Jika message adalah Nothing, string kosong digunakan.

severity
TraceEventType

Jenis pesan. Secara bawaan, TraceEventType.Information.

id
Int32

Pengidentifikasi pesan, biasanya digunakan untuk korelasi. Secara default, terkait dengan entryType seperti yang dijelaskan dalam tabel.

Pengecualian

Jenis pesan bukan salah TraceEventType satu nilai enumerasi.

Kode dengan kepercayaan parsial memanggil metode , tetapi menulis ke pendengar log peristiwa yang memerlukan kepercayaan penuh.

Contoh

Contoh ini menunjukkan cara menggunakan My.Application.Log.WriteEntry metode untuk mencatat informasi pelacakan. Untuk informasi selengkapnya, lihat Cara: Menulis Pesan Log.

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

Contoh kode ini hanya dapat berjalan dalam aplikasi klien. Ubah My.Application.Log.WriteEntry ke My.Log.WriteEntry untuk aplikasi Web.

Keterangan

Metode ini WriteEntry menulis pesan ke pendengar log peristiwa aplikasi.

Dalam aplikasi klien, Log objek tersedia melalui My.Application.Log objek . Dalam aplikasi Web, Log objek tersedia melalui My.Log objek .

Untuk mempelajari pendengar log mana yang menerima WriteEntry pesan metode, lihat Panduan: Menentukan Di Mana Informasi Penulisan My.Application.Log. Anda dapat mengubah pendengar log default. Untuk informasi selengkapnya, lihat Bekerja dengan Log Aplikasi.

Untuk kelebihan beban yang tidak mengambil id argumen, id yang ditulis ke log ditentukan oleh tabel berikut.

severity id default
Information 0
Warning 1
Error 2
Critical 3
Start 4
Stop 5
Suspend 6
Resume 7
Verbose 8
Transfer 9

Tabel berikut ini mencantumkan contoh tugas yang melibatkan WriteEntry metode .

Untuk Lihat
Menulis informasi peristiwa ke pendengar log aplikasi Cara: Menulis Pesan Log
Menentukan tempat Log menulis informasi Panduan: Menentukan Di mana My.Application.Log Menulis Informasi

Ketersediaan menurut Jenis Proyek

Jenis proyek Available
Aplikasi Windows Yes
Pustaka Kelas Yes
Aplikasi Konsol Yes
Pustaka Kontrol Windows Yes
Perpustakaan Kontrol Situs Web Tidak
Layanan Windows Yes
Situs Web Yes

Lihat juga

Berlaku untuk