EventLogEntry Class
Encapsulates a single record in the event log. This class cannot be inherited.
For a list of all members of this type, see EventLogEntry Members.
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Diagnostics.EventLogEntry
[Visual Basic] <Serializable> NotInheritable Public Class EventLogEntry Inherits Component Implements ISerializable [C#] [Serializable] public sealed class EventLogEntry : Component, ISerializable [C++] [Serializable] public __gc __sealed class EventLogEntry : public Component, ISerializable [JScript] public Serializable class EventLogEntry extends Component implements ISerializable
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
You usually will not create instances of EventLogEntry directly when working with the EventLog class. The Entries member of the EventLog class contains a collection of EventLogEntry instances, which you iterate over when reading by using the EventLogEntryCollection.Item class index member.
Example
[Visual Basic] Imports System Imports System.Diagnostics Class MyEventlogClass Public Shared Sub Main() Dim myEventType As String = Nothing ' Associate the instance of 'EventLog' with local System Log. Dim myEventLog As New EventLog("System", ".") Console.WriteLine("1:Error") Console.WriteLine("2:Information") Console.WriteLine("3:Warning") Console.WriteLine("Select the Event Type") Dim myOption As Integer = Convert.ToInt32(Console.ReadLine()) Select Case myOption Case 1 myEventType = "Error" Case 2 myEventType = "Information" Case 3 myEventType = "Warning" Case Else End Select Dim myLogEntryCollection As EventLogEntryCollection = myEventLog.Entries Dim myCount As Integer = myLogEntryCollection.Count ' Iterate through all 'EventLogEntry' instances in 'EventLog'. Dim i As Integer For i = myCount - 1 To -1 Step -1 Dim myLogEntry As EventLogEntry = myLogEntryCollection(i) ' Select the entry having desired EventType. If myLogEntry.EntryType.ToString().Equals(myEventType) Then ' Display Source of the event. Console.WriteLine(myLogEntry.Source + " was the source of last "& _ "event of type " & myLogEntry.EntryType.ToString()) Return End If Next i End Sub 'Main End Class 'MyEventlogClass [C#] using System; using System.Diagnostics; class MyEventlogClass { public static void Main() { String myEventType=null; // Associate the instance of 'EventLog' with local System Log. EventLog myEventLog = new EventLog("System", "."); Console.WriteLine("1:Error"); Console.WriteLine("2:Information"); Console.WriteLine("3:Warning"); Console.WriteLine("Select the Event Type"); int myOption=Convert.ToInt32(Console.ReadLine()); switch(myOption) { case 1: myEventType="Error"; break; case 2: myEventType="Information"; break; case 3: myEventType="Warning"; break; default: break; } EventLogEntryCollection myLogEntryCollection=myEventLog.Entries; int myCount =myLogEntryCollection.Count; // Iterate through all 'EventLogEntry' instances in 'EventLog'. for(int i=myCount-1;i>0;i--) { EventLogEntry myLogEntry = myLogEntryCollection[i]; // Select the entry having desired EventType. if(myLogEntry.EntryType.ToString().Equals(myEventType)) { // Display Source of the event. Console.WriteLine(myLogEntry.Source +" was the source of last event of type " +myLogEntry.EntryType); return; } } } } [C++] #using <mscorlib.dll> #using <System.dll> using namespace System; using namespace System::Diagnostics; void main() { String* myEventType = 0; // Associate the instance of 'EventLog' with local System Log. EventLog* myEventLog = new EventLog(S"System", S"."); Console::WriteLine(S"1:Error"); Console::WriteLine(S"2:Information"); Console::WriteLine(S"3:Warning"); Console::WriteLine(S"Select the Event Type"); int myOption=Convert::ToInt32(Console::ReadLine()); switch (myOption) { case 1: myEventType=S"Error"; break; case 2: myEventType=S"Information"; break; case 3: myEventType=S"Warning"; break; default: break; } EventLogEntryCollection* myLogEntryCollection = myEventLog->Entries; int myCount = myLogEntryCollection->Count; // Iterate through all 'EventLogEntry' instances in 'EventLog'. for (int i=myCount-1; i>0; i--) { EventLogEntry* myLogEntry = myLogEntryCollection->Item[i]; // Select the entry having desired EventType. if (__box(myLogEntry->EntryType)->Equals(myEventType)) { // Display Source of the event. Console::WriteLine(S"{0} was the source of last event of type {1}", myLogEntry->Source, __box(myLogEntry->EntryType)); return; } } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Diagnostics
Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
See Also
EventLogEntry Members | System.Diagnostics Namespace | EventLog | EventLogEntryCollection