Log.WriteEntry メソッド

定義

アプリケーションのログ リスナーにメッセージを書き込みます。

オーバーロード

名前 説明
WriteEntry(String)

アプリケーションのログ リスナーにメッセージを書き込みます。

WriteEntry(String, TraceEventType)

アプリケーションのログ リスナーにメッセージを書き込みます。

WriteEntry(String, TraceEventType, Int32)

アプリケーションのログ リスナーにメッセージを書き込みます。

WriteEntry(String)

アプリケーションのログ リスナーにメッセージを書き込みます。

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

パラメーター

message
String

必須。 ログに記録するメッセージ。 messageNothingされている場合は、空の文字列が使用されます。

例外

部分信頼を持つコードはメソッドを呼び出しますが、完全信頼を必要とするイベント ログ リスナーに書き込みます。

この例では、 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.WriteEntryを Web アプリケーションのMy.Log.WriteEntryに変更します。

注釈

WriteEntry メソッドは、アプリケーションのイベント ログ リスナーにメッセージを書き込みます。

クライアント アプリケーションでは、 Log オブジェクトは、 My.Application.Log オブジェクトを介して使用できます。 Web アプリケーションでは、 Log オブジェクトは My.Log オブジェクトを介して使用できます。

WriteEntry メソッドのメッセージを受信するログ リスナーについては、「チュートリアル: My.Application.Log が情報を書き込む場所を決定する」を参照してください。 既定のログ リスナーを変更できます。 詳細については、「 アプリケーション ログの操作」を参照してください。

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 メソッドに関連するタスクの例を示します。

ターゲット 参照先
アプリケーションのログ リスナーにイベント情報を書き込む 方法: ログ メッセージを書き込む
Logが情報を書き込む場所を決定する チュートリアル: My.Application.Log が情報を書き込む場所の決定

プロジェクトの種類別の可用性

プロジェクト タイプ 在庫有り
Windows アプリケーション Yes
クラス ライブラリ Yes
コンソール アプリケーション Yes
Windows コントロール ライブラリ Yes
Web コントロール ライブラリ いいえ
Windows サービス Yes
ウェブサイト Yes

こちらもご覧ください

適用対象

WriteEntry(String, TraceEventType)

アプリケーションのログ リスナーにメッセージを書き込みます。

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)

パラメーター

message
String

必須。 ログに記録するメッセージ。 messageNothingされている場合は、空の文字列が使用されます。

severity
TraceEventType

メッセージの種類。 既定では TraceEventType.Information です。

例外

メッセージの種類は、 TraceEventType 列挙値の 1 つではありません。

部分信頼を持つコードはメソッドを呼び出しますが、完全信頼を必要とするイベント ログ リスナーに書き込みます。

この例では、 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.WriteEntryを Web アプリケーションのMy.Log.WriteEntryに変更します。

注釈

WriteEntry メソッドは、アプリケーションのイベント ログ リスナーにメッセージを書き込みます。

クライアント アプリケーションでは、 Log オブジェクトは、 My.Application.Log オブジェクトを介して使用できます。 Web アプリケーションでは、 Log オブジェクトは My.Log オブジェクトを介して使用できます。

WriteEntry メソッドのメッセージを受信するログ リスナーについては、「チュートリアル: My.Application.Log が情報を書き込む場所を決定する」を参照してください。 既定のログ リスナーを変更できます。 詳細については、「 アプリケーション ログの操作」を参照してください。

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 メソッドに関連するタスクの例を示します。

ターゲット 参照先
アプリケーションのログ リスナーにイベント情報を書き込む 方法: ログ メッセージを書き込む
Logが情報を書き込む場所を決定する チュートリアル: My.Application.Log が情報を書き込む場所の決定

プロジェクトの種類別の可用性

プロジェクト タイプ 在庫有り
Windows アプリケーション Yes
クラス ライブラリ Yes
コンソール アプリケーション Yes
Windows コントロール ライブラリ Yes
Web コントロール ライブラリ いいえ
Windows サービス Yes
ウェブサイト Yes

こちらもご覧ください

適用対象

WriteEntry(String, TraceEventType, Int32)

アプリケーションのログ リスナーにメッセージを書き込みます。

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)

パラメーター

message
String

必須。 ログに記録するメッセージ。 messageNothingされている場合は、空の文字列が使用されます。

severity
TraceEventType

メッセージの種類。 既定では TraceEventType.Information です。

id
Int32

メッセージ識別子。通常、関連付けに使用されます。 既定では、表の説明に従って entryType に関連します。

例外

メッセージの種類は、 TraceEventType 列挙値の 1 つではありません。

部分信頼を持つコードはメソッドを呼び出しますが、完全信頼を必要とするイベント ログ リスナーに書き込みます。

この例では、 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.WriteEntryを Web アプリケーションのMy.Log.WriteEntryに変更します。

注釈

WriteEntry メソッドは、アプリケーションのイベント ログ リスナーにメッセージを書き込みます。

クライアント アプリケーションでは、 Log オブジェクトは、 My.Application.Log オブジェクトを介して使用できます。 Web アプリケーションでは、 Log オブジェクトは My.Log オブジェクトを介して使用できます。

WriteEntry メソッドのメッセージを受信するログ リスナーについては、「チュートリアル: My.Application.Log が情報を書き込む場所を決定する」を参照してください。 既定のログ リスナーを変更できます。 詳細については、「 アプリケーション ログの操作」を参照してください。

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 メソッドに関連するタスクの例を示します。

ターゲット 参照先
アプリケーションのログ リスナーにイベント情報を書き込む 方法: ログ メッセージを書き込む
Logが情報を書き込む場所を決定する チュートリアル: My.Application.Log が情報を書き込む場所の決定

プロジェクトの種類別の可用性

プロジェクト タイプ 在庫有り
Windows アプリケーション Yes
クラス ライブラリ Yes
コンソール アプリケーション Yes
Windows コントロール ライブラリ Yes
Web コントロール ライブラリ いいえ
Windows サービス Yes
ウェブサイト Yes

こちらもご覧ください

適用対象