Searches for all event logs on the given computer and creates an array of EventLog objects to contain the list.
[Visual Basic] Overloads Public Shared Function GetEventLogs( _ ByVal machineName As String _ ) As EventLog () [C#] public static EventLog[] GetEventLogs( string machineName ); [C++] public: static EventLog* GetEventLogs( String* machineName ) []; [JScript] public static function GetEventLogs( machineName : String ) : EventLog[];
An array of type EventLog that represents the logs on the given computer.
Exception Type | Condition |
---|---|
ArgumentException | The machineName parameter is an invalid computer name. |
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 computer specified by the machineName parameter 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 specified 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 computer "myComputer". It then outputs the name of each log.
Import the System.Diagnostics namespace for this example.
[Visual Basic]
Private Sub GetRemoteLogList() '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 specified computer. EventLogList = EventLog.GetEventLogs("myComputer") 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 | MachineName