Export (0) Print
Expand All

EventLog.GetEventLogs Method (String)

Searches for all event logs on the given computer and creates an array of EventLog objects that contain the list.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public:
static array<EventLog^>^ GetEventLogs (
	String^ machineName
)
public static EventLog[] GetEventLogs (
	String machineName
)
public static function GetEventLogs (
	machineName : String
) : EventLog[]

Parameters

machineName

The computer on which to search for event logs.

Return Value

An array of type EventLog that represents the logs on the given computer.

Exception typeCondition

ArgumentException

The machineName parameter is an invalid computer name.

SystemException

You do not 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 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 usually includes at least three logs: Application, System, and Security. If you created custom logs on the specified computer, they will appear in the array as well.

GetEventLogs is a static method, so it can be called on the EventLog class itself. It is not necessary to create an instance of an EventLog object to make a call to the method.

To retrieve the list of event logs, you must have the appropriate registry permissions. These permissions are identical to those required to call Exists and SourceExists.

The following example gets a list of logs on the computer "myServer". It then outputs the name of each log.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
   array<EventLog^>^remoteEventLogs;
   remoteEventLogs = EventLog::GetEventLogs( "myServer" );
   Console::WriteLine( "Number of logs on computer: {0}", remoteEventLogs->Length );
   System::Collections::IEnumerator^ myEnum = remoteEventLogs->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      EventLog^ log = safe_cast<EventLog^>(myEnum->Current);
      Console::WriteLine( "Log: {0}", log->Log );
   }
}


import System.*;
import System.Diagnostics.*;
import System.Threading.*;

class MySample
{
    public static void main(String[] args)
    {
        EventLog remoteEventLogs[];
        remoteEventLogs = EventLog.GetEventLogs("myServer");
        Console.WriteLine("Number of logs on computer: " 
            + remoteEventLogs.length);
        for (int iCtr = 0; iCtr < remoteEventLogs.length; iCtr++) {
            EventLog log = remoteEventLogs[iCtr];
            Console.WriteLine("Log: " + log.get_Log());
        }
    } //main
} //MySample

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft