Export (0) Print
Expand All

EventLog.Entries Property

Gets the contents of the event log.

[Visual Basic]
Public ReadOnly Property Entries As EventLogEntryCollection
[C#]
public EventLogEntryCollection Entries {get;}
[C++]
public: __property EventLogEntryCollection* get_Entries();
[JScript]
public function get Entries() : EventLogEntryCollection;

Property Value

An EventLogEntryCollection holding the entries in the event log. Each entry is associated with an instance of the EventLogEntry class.

Remarks

Use the Entries member when reading from the event log.

Because the property is read-only, you cannot modify an entry or write to the log using Entries. Instead, specify a Source and call WriteEntry to write a new log entry. You can use Entries to count the number of entries in the event log, and view each EventLogEntry in the collection. Use the indexed Item member to retrieve information about a specific entry, such as Message, Category, TimeWritten, or EntryType.

It is not necessary to specify a Source when only reading from a log. You can specify only the Log name and MachineName (server computer name) properties for the EventLog instance. In either case, the Entries member is automatically populated with the event log's list of entries. You can select the appropriate index for an item in this list to read individual entries.

An important distinction between reading and writing log entries is that it is not necessary to explicitly call a read method. Once the Log and MachineName are specified, the Entries property is automatically populated. If you change the value of the Log or MachineName property, the Entries property is repopulated the next time you read it.

Note   You are not required to specify the MachineName if you are connecting to a log. If you do not specify the MachineName, the local computer, ".", is assumed.

Example

[Visual Basic, C#, C++] The following example reads entries in the event log, "MyNewLog", on the local computer.

[Visual Basic] 
Option Strict
Option Explicit

Imports System
Imports System.Diagnostics
Imports Microsoft.VisualBasic

Class MySample
    Public Shared Sub Main()
        
        Dim myLog As New EventLog()
        myLog.Log = "MyNewLog"
        Dim entry As EventLogEntry
        For Each entry In  myLog.Entries
            Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
        Next entry
    End Sub ' Main
End Class ' MySample

[C#] 
using System;
using System.Diagnostics;
              
class MySample{

    public static void Main(){

        EventLog myLog = new EventLog();
        myLog.Log = "MyNewLog";                      
        foreach(EventLogEntry entry in myLog.Entries){
            Console.WriteLine("\tEntry: " + entry.Message);
        }    
    }       
}
   

[C++] 
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;

int main(){

    EventLog* myLog = new EventLog();
    myLog->Log = S"MyNewLog";                      
    System::Collections::IEnumerator* myEnum = myLog->Entries->GetEnumerator();
    while (myEnum->MoveNext())
    {
        EventLogEntry* entry = __try_cast<EventLogEntry*>(myEnum->Current);
        Console::WriteLine(S"\tEntry: {0}", entry->Message);
    }    
}       

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace | EventLogEntryCollection | EventLogEntry | Source | Log | MachineName | WriteEntry

Show:
© 2014 Microsoft