EventLogEntry.InstanceId プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
イベント エントリのメッセージ テキストを指定するリソース識別子を取得します。
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 = 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 );
// 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 、 InstanceId と等しく、上位 2 ビットがマスクオフされています。 同じソースの 2 つのイベント ログ エントリは一致する EventID 値を持つことができますが、リソース識別子の上位 2 ビットの違いにより、値が異なります InstanceId 。
アプリケーションがいずれかのメソッドを使用してイベント エントリを WriteEntry 書き込んだ場合、 プロパティは InstanceId 省略可能な eventId
パラメーターと一致します。 アプリケーションが を使用して WriteEventイベントを書き込んだ場合、 プロパティは InstanceId 、 パラメーターの で InstanceId 指定されたリソース識別子と instance
一致します。 アプリケーションが Windows API ReportEvent
を使用してイベントを書き込んだ場合、 プロパティは InstanceId パラメーターで指定されたリソース識別子と dwEventID
一致します。
イベント メッセージの定義とイベント ログ リソース ファイルの構築の詳細については、プラットフォーム SDK ドキュメントの メッセージ コンパイラ に関する記事を参照してください。 イベント ログ識別子の詳細については、プラットフォーム SDK ドキュメントの イベント識別子に関する 記事を参照してください。