NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Reading Event Log Entries

You use the Entries collection to look at the entries in a particular event log. You can use standard collection properties such as All, Count, and Item to work with the elements the collection contains. You might read event log entries to find out more information about a problem that occurred in your system, to identify usage patterns, or to identify problems (such as a failing hard drive) before they cause damage.

Note   The Entries collection is read-only; to write a message to a log you must use the WriteEntry method. For information, see Writing Entries to Event Logs .

If you ask for the count of entries in a new custom log that has not yet been written to, the system will return the count of the entries in the Application log on that server. Make sure that logs you are counting have been created and written to in order to avoid this problem.

To read event log entries

  1. Create an instance of the EventLog component. For details, see Creating EventLog Components .
  2. Set the Log and MachineName properties for the component, if necessary. For details, see Configuring EventLog Components.
  3. Use the Entries collection to review the entries in the log.
The resulting code might look like the following:
[Visual Basic]
Dim en As EventLogEntry
For Each en In EventLog1.Entries
   Debug.Print en.Message
Next en
Dim enArr() As EventLogEntry
EnArr = EventLog1.Entries.All
[C#]
EventLogEntry en;
EventLogEntry[] enArr;
foreach (en in EventLog1.Entries) {
   Debug.Print en.Message;
}
EnArr = EventLog1.Entries.All;

See Also

Introduction to the EventLog Component  | Handling the EntryWritten Event