EventLogEntry.InstanceId プロパティ
アセンブリ: System (system.dll 内)


InstanceId プロパティは、構成済みのイベント ソースのイベント エントリを一意に識別します。イベント ログ エントリの InstanceId は、イベント ソースのメッセージ リソース ファイル内のイベントについて、32 ビットの完全なリソース識別子を表します。EventID プロパティは、上位 2 ビットのマスクがオフになっている InstanceId と等価です。同じソース内の 2 つのイベント ログ エントリに、一致する EventID 値を設定できますが、リソース識別子の上位 2 ビットの違いにより、InstanceId 値は異なります。
アプリケーションが WriteEntry メソッドのいずれかを使用してイベント エントリを書き込んだ場合、InstanceId プロパティはオプションの eventId パラメータと一致します。アプリケーションが WriteEvent を使用してイベントを書き込んだ場合、InstanceId プロパティは、instance パラメータの InstanceId で指定されたリソース識別子と一致します。アプリケーションが Win32 API ReportEvent を使用してイベントを書き込んだ場合、InstanceId プロパティは、dwEventID パラメータで指定されたリソース識別子と一致します。
イベント メッセージの定義およびイベント ログ リソース ファイルの作成の詳細については、http://msdn.microsoft.com のプラットフォーム SDK ドキュメントで「Message Compiler」のトピックを参照してください。イベント ログ識別子の詳細については、プラットフォーム SDK の「イベント識別子」のトピックを参照してください。

特定のリソース識別子を持つエントリのイベント ログを検索するコード例を次に示します。このコード例は、一致する各エントリのイベント メッセージを表示し、ログ内の一致するエントリの合計数をカウントします。各エントリのメッセージ テキストは、同じ場合もあれば、異なる場合もあります。各イベント メッセージは、書き込み時に使用されたイベント ソース メッセージ ファイル、挿入文字列、およびパラメータによって異なります。
' 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)
// 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. String^ myLogName = EventLog::LogNameFromSourceName( sourceName, "." ); // Find each instance of a specific event log entry in a // particular event log. EventLog^ myEventLog = gcnew EventLog( myLogName,"." ); int count = 0; Console::WriteLine( "Searching event log entries for the event ID {0}...", ServerConnectionDownMsgId ); // Search for the resource ID, display the event text, // and display the number of matching entries. System::Collections::IEnumerator^ myEnum = myEventLog->Entries->GetEnumerator(); while ( myEnum->MoveNext() ) { EventLogEntry^ entry = safe_cast<EventLogEntry^>(myEnum->Current); if ( entry->InstanceId == ServerConnectionDownMsgId ) { count++; Console::WriteLine(); Console::WriteLine( "Entry ID = {0}", entry->InstanceId ); Console::WriteLine( "Reported at {0}", entry->TimeWritten ); 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, ServerConnectionDownMsgId, myLogName );

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からEventLogEntry.InstanceId プロパティを検索する場合は、下記のリンクをクリックしてください。

- EventLogEntry.InstanceId プロパティのページへのリンク