EventLog.Entries Property

Definition

Gets the contents of the event log.

C#
[System.ComponentModel.Browsable(false)]
public System.Diagnostics.EventLogEntryCollection Entries { get; }

Property Value

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

Attributes

Examples

The following example reads entries in the event log, "MyNewLog", on the local computer.

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);
        }
    }
}

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. After 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.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also