Searches for all event logs on the local computer and creates an array of EventLog objects to contain the list.
[Visual Basic] Overloads Public Shared Function GetEventLogs() As EventLog () [C#] public static EventLog[] GetEventLogs(); [C++] public: static EventLog* GetEventLogs() []; [JScript] public static function GetEventLogs() : EventLog[];
An array of type EventLog that represents the logs on the local computer.
Exception Type | Condition |
---|---|
SystemException | You don't have read access to the registry.
-or- There is no event log service on the computer. |
The array of EventLog objects is a snapshot of all event logs that are on the local computer when the call to GetEventLogs is made. This is not a dynamic collection, so it does not reflect the deletion or creation of logs in real time. You should verify that a log in the array exists before you read or write to it. The array will usually include at least three logs, Application, System, and Security. If you have created custom logs on the local computer, they appear in the array as well.
GetEventLogs is a static (in Visual Basic Shared) method, so it can be called on the EventLog class itself. It is not necessary to instantiate an EventLog object to make a call to the method.
The following example gets a list of logs on the local computer. It then outputs the name of each log.
Import the System.Diagnostics namespace for this example.
[Visual Basic]
Private Sub GetLogList() 'Declare an array of event logs. Dim EventLogList() As EventLog 'This is used in a for loop Dim i As Integer 'Show the name of each event log on the local computer. EventLogList = EventLog.GetEventLogs For i = 0 To EventLogList.Length - 1 Console.WriteLine(EventLogList(i).Log) Next End Sub
EventLog Class | EventLog Members | System.Diagnostics Namespace | EventLog.GetEventLogs Overload List | Exists | Log