EventLogEntry.InstanceId Właściwość

Definicja

Pobiera identyfikator zasobu, który wyznacza tekst komunikatu wpisu zdarzenia.

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

Wartość właściwości

Identyfikator zasobu, który odpowiada definicji ciągu w pliku zasobu komunikatu źródła zdarzeń.

Atrybuty

Przykłady

Poniższy przykład kodu wyszukuje dziennik zdarzeń dla wpisów o określonym identyfikatorze zasobu. Przykładowy kod wyświetla komunikat zdarzenia dla każdego pasującego wpisu i zlicza łączną liczbę pasujących wpisów w dzienniku. Tekst wiadomości dla każdego wpisu może lub nie może być taki sam; każdy komunikat zdarzenia zależy od pliku komunikatu źródła zdarzeń, ciągów wstawiania i parametrów używanych podczas zapisywania.


// 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)

Uwagi

Właściwość InstanceId jednoznacznie identyfikuje wpis zdarzenia dla skonfigurowanego źródła zdarzeń. Wpis InstanceId dziennika zdarzeń reprezentuje pełny 32-bitowy identyfikator zasobu zdarzenia w pliku zasobu komunikatu dla źródła zdarzeń. Właściwość EventID jest równa InstanceId z dwóch pierwszych bitów zamaskowanych. Dwa wpisy dziennika zdarzeń z tego samego źródła mogą mieć pasujące EventID wartości, ale mają różne InstanceId wartości z powodu różnic w dwóch pierwszych bitach identyfikatora zasobu.

Jeśli aplikacja napisała wpis zdarzenia przy użyciu jednej z WriteEntry metod, InstanceId właściwość jest zgodna z opcjonalnym eventId parametrem. Jeśli aplikacja napisała zdarzenie przy użyciu polecenia WriteEvent, InstanceId właściwość jest zgodna z identyfikatorem zasobu określonym w InstanceId parametrze instance . Jeśli aplikacja napisała zdarzenie przy użyciu interfejsu API ReportEventsystemu Windows, InstanceId właściwość jest zgodna z identyfikatorem zasobu określonym w parametrze dwEventID .

Aby uzyskać szczegółowe informacje na temat definiowania komunikatów o zdarzeniach i tworzenia plików zasobów dziennika zdarzeń, zobacz artykuł Kompilator komunikatów w dokumentacji zestawu SDK platformy. Aby uzyskać szczegółowe informacje o identyfikatorach dziennika zdarzeń, zobacz artykuł Identyfikatory zdarzeń w dokumentacji zestawu SDK platformy.

Dotyczy

Zobacz też