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 = 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 . 동일한 원본의 두 이벤트 로그 항목은 일치하는 EventID 값을 가질 수 있지만 리소스 식별자의 상위 두 비트 차이로 인해 값이 다를 InstanceId 수 있습니다.

애플리케이션 중 하나를 사용 하는 이벤트 항목을 작성 하는 경우는 WriteEntry 메서드를 InstanceId 속성이 선택적 일치 eventId 매개 변수입니다. 애플리케이션을 사용 하 여 이벤트를 작성 하는 경우 WriteEventInstanceId 속성에 지정 된 리소스 식별자와 일치 합니다 InstanceIdinstance 매개 변수입니다. 애플리케이션에서 Windows API ReportEvent를 사용하여 이벤트를 작성한 경우 속성은 InstanceId 매개 변수에 dwEventID 지정된 리소스 식별자와 일치합니다.

이벤트 메시지를 정의하고 이벤트 로그 리소스 파일을 빌드하는 방법에 대한 자세한 내용은 플랫폼 SDK 설명서의 메시지 컴파일러 문서를 참조하세요. 이벤트 로그 식별자에 대한 자세한 내용은 플랫폼 SDK 설명서의 이벤트 식별자 문서를 참조하세요.

적용 대상

추가 정보