Gets the contents of the event log.
[Visual Basic] Overridable Public ReadOnly Property Entries As _ EventLog.EventLogEntryCollection [C#] public EventLog.EventLogEntryCollection Entries {virtual get;} [C++] public: __property virtual EventLog.EventLogEntryCollection* get_Entries(); [JScript] public function get Entries() : EventLog.EventLogEntryCollection;
An EventLog.EventLogEntryCollection that holds the EventLogEntry items in the event log.
Use the Entries member when reading from the event log.
Because the property is read-only, you can't 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 all entries or an EventLogEntry in the collection. Use the indexed Item property (EventLogEntryCollection indexer)member to retrieve information about a specific entry, such as Message, Category, TimeWritten and 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) 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.
Note You are not explicitly required to specify the MachineName if you are connecting to a log by specifying a Log/ MachineName pair. If you do not specify the MachineName, the local computer, ".", is assumed.
The following example uses the Log and MachineName of an EventLog to connect to an event log. Then it displays the Entries in the log.
Because the procedure reads rather than writes entries, it is only necessary to set the Log and MachineName. The Source is only necessary for WriteEntry. Alternately, you can leave the MachineName empty and the local computer will be assumed.
This example assumes you already have a custom event log "myNewLog" on the computer named "myComputer".
Import the System.Diagnostics namespace for this example.
[Visual Basic]
Private Sub GetLogEntries() 'Declare a new event log Dim evtLog As EventLog 'This is used in the for loop iterating through the evtLog.Entries Dim entry As EventLogEntry 'Instantiate an event log. evtLog = New EventLog 'Set the server and log names so we can read from the log. evtLog.MachineName = "myComputer" evtLog.Log = "myNewLog" 'Display the entries in order to the screen. For Each entry In evtLog.Entries Console.WriteLine("Message: " + entry.Message) Next End Sub
EventLog Class | EventLog Members | System.Diagnostics Namespace | EventLog.EventLogEntryCollection | EventLogEntry | Source | Log | MachineName | WriteEntry