次の方法で共有


EventLogEntry.InstanceId プロパティ

定義

イベント エントリのメッセージ テキストを指定するリソース識別子を取得します。

public:
 property long InstanceId { long get(); };
public long InstanceId { get; }
[System.Runtime.InteropServices.ComVisible(false)]
public long InstanceId { get; }
member this.InstanceId : int64
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.InstanceId : int64
Public ReadOnly Property InstanceId As Long

プロパティ値

イベント ソースのメッセージ リソース ファイル内の文字列定義に対応するリソース識別子。

属性

次のコード例では、イベント ログで特定のリソース識別子を持つエントリを検索します。 このコード例では、一致するエントリごとにイベント メッセージを表示し、ログ内の一致するエントリの合計数をカウントします。 各エントリのメッセージ テキストは、同じである場合とそうでない場合があります。各イベント メッセージは、イベント ソース メッセージ ファイル、挿入文字列、および書き込み時に使用されるパラメーターによって異なります。

// Get the event log corresponding to the existing source.
string myLogName = EventLog.LogNameFromSourceName(sourceName,".");

// Find each instance of a specific event log entry in a
// particular event log.

EventLog myEventLog = new EventLog(myLogName, ".");
int count = 0;

Console.WriteLine("Searching event log entries for the event ID {0}...",
    ServerConnectionDownMsgId.ToString());

// Search for the resource ID, display the event text,
// and display the number of matching entries.

foreach(EventLogEntry entry in myEventLog.Entries)
{
    if (entry.InstanceId == ServerConnectionDownMsgId)
    {
        count ++;
        Console.WriteLine();
        Console.WriteLine("Entry ID    = {0}",
            entry.InstanceId.ToString());
        Console.WriteLine("Reported at {0}",
            entry.TimeWritten.ToString());
        Console.WriteLine("Message text:");
        Console.WriteLine("\t{0}", entry.Message);
    }
}
Console.WriteLine();
Console.WriteLine("Found {0} events with ID {1} in event log {2}.",
    count.ToString(), ServerConnectionDownMsgId.ToString(), myLogName);
    ' Get the event log corresponding to the existing source.
    Dim myLogName As String = EventLog.LogNameFromSourceName(sourceName,".")

    ' Find each instance of a specific event log entry in a
    ' particular event log.

    Dim myEventLog As EventLog = new EventLog(myLogName, ".", sourceName)
    Dim count As Integer = 0

    Console.WriteLine("Searching event log entries for the event ID {0}...", _
       ServerConnectionDownMsgId.ToString())
    
    ' Search for the resource ID, display the event text,
    ' and display the number of matching entries.

    Dim entry As EventLogEntry
    For Each entry In  myEventLog.Entries
        If entry.InstanceId = ServerConnectionDownMsgId
            count = count + 1
            Console.WriteLine()
            Console.WriteLine("Entry ID    = {0}", _
                entry.InstanceId.ToString())
            Console.WriteLine("Reported at {0}", _
                entry.TimeWritten.ToString())
            Console.WriteLine("Message text:")
            Console.WriteLine(ControlChars.Tab + entry.Message)
        End If
    Next entry

    Console.WriteLine()
    Console.WriteLine("Found {0} events with ID {1} in event log {2}", _
        count.ToString(), ServerConnectionDownMsgId.ToString(), myLogName)

注釈

InstanceId プロパティは、構成されたイベント ソースのイベント エントリを一意に識別します。 イベント ログ エントリの InstanceId は、イベント ソースのメッセージ リソース ファイル内のイベントの完全な 32 ビット リソース識別子を表します。 EventID プロパティは、上位 2 ビットがマスクされたInstanceIdと等しくなります。 同じソースの 2 つのイベント ログ エントリは、一致する EventID 値を持つことができますが、リソース識別子の上位 2 ビットの違いにより、 InstanceId 値が異なります。

アプリケーションが WriteEntry メソッドのいずれかを使用してイベント エントリを記述した場合、 InstanceId プロパティは省略可能な eventId パラメーターと一致します。 アプリケーションが WriteEvent を使用してイベントを記述した場合、InstanceId プロパティは、instance パラメーターのInstanceIdで指定されたリソース識別子と一致します。 アプリケーションが Windows API ReportEventを使用してイベントを記述した場合、 InstanceId プロパティは、 dwEventID パラメーターで指定されたリソース識別子と一致します。

イベント メッセージの定義とイベント ログ リソース ファイルの構築の詳細については、Platform SDK ドキュメントの メッセージ コンパイラ の記事を参照してください。 イベント ログ識別子の詳細については、プラットフォーム SDK ドキュメントの イベント識別子に関する 記事を参照してください。

適用対象

こちらもご覧ください