.NET Framework Class Library 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)

Syntax
Public Shared Function GetEventLogs ( _
machineName As String _
) As EventLog()
public static EventLog[] GetEventLogs(
string machineName
)
public:
static array<EventLog^>^ GetEventLogs(
String^ machineName
)
static member GetEventLogs :
machineName:string -> EventLog[]
Parameters- machineName
- Type: System..::.String
The computer on which to search for event logs.

Exceptions
| Exception | Condition |
|---|
| ArgumentException | The machineName parameter is an invalid computer name. | | InvalidOperationException | You do not have read access to the registry. -or- There is no event log service on the computer. |

Remarks
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.

Examples
The following example gets a list of logs on the computer "myServer". It then outputs the name of each log.
Imports System
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
Dim remoteEventLogs() As EventLog
remoteEventLogs = EventLog.GetEventLogs("myServer")
Console.WriteLine(("Number of logs on computer: " & remoteEventLogs.Length))
Dim log As EventLog
For Each log In remoteEventLogs
Console.WriteLine(("Log: " & log.Log))
Next log
End Sub ' Main
End Class ' MySample
using System;
using System.Diagnostics;
using System.Threading;
class MySample{
public static void Main(){
EventLog[] remoteEventLogs;
remoteEventLogs = EventLog.GetEventLogs("myServer");
Console.WriteLine("Number of logs on computer: " + remoteEventLogs.Length);
foreach(EventLog log in remoteEventLogs){
Console.WriteLine("Log: " + log.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 );
}
}

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0 .NET Framework Client ProfileSupported in: 4, 3.5 SP1

.NET Framework Security

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

See Also
|
.NET Framework-Klassenbibliothek EventLog..::.GetEventLogs-Methode (String) Sucht nach allen Ereignisprotokollen auf dem angegebenen Computer und erstellt ein Array von EventLog-Objekten, das die Liste enthält.
Namespace:
System.Diagnostics
Assembly:
System (in System.dll)

Syntax
Public Shared Function GetEventLogs ( _
machineName As String _
) As EventLog()
public static EventLog[] GetEventLogs(
string machineName
)
public:
static array<EventLog^>^ GetEventLogs(
String^ machineName
)
static member GetEventLogs :
machineName:string -> EventLog[]
Parameter- machineName
- Typ: System..::.String
Der Computer, auf dem nach Ereignisprotokollen gesucht werden soll.

Ausnahmen
| Ausnahme | Bedingung |
|---|
| ArgumentException | Der machineName-Parameter ist ein ungültiger Computername. | | InvalidOperationException | Sie verfügen nicht über Lesezugriff auf die Registrierung. – oder – Auf dem Computer ist kein Ereignisprotokolldienst vorhanden. |

Hinweise
Das Array von EventLog-Objekten stellt eine Momentaufnahme aller Ereignisprotokolle dar, die zum Zeitpunkt des Aufrufs von GetEventLogs auf dem durch den machineName-Parameter angegebenen Computer vorhanden sind. Dies ist keine dynamische Auflistung, d. h., das Löschen und Erstellen von Protokollen wird nicht in Echtzeit wiedergegeben. Stellen Sie sicher, dass das Protokoll im Array vorhanden ist, bevor Sie aus diesem lesen oder in dieses schreiben. Das Array enthält normalerweise mindestens drei Protokolle: das Anwendungs-, das System- und das Sicherheitsprotokoll. Wenn Sie auf dem angegebenen Computer benutzerdefinierte Protokolle erstellt haben, werden diese ebenfalls in das Array aufgenommen.
GetEventLogs ist eine static-Methode und kann daher für die EventLog-Klasse selbst aufgerufen werden. Es ist nicht erforderlich, eine Instanz eines EventLog-Objekts zu erstellen, um die Methode aufzurufen. Zum Abfragen der Liste der Ereignisprotokolle benötigen Sie die entsprechenden Berechtigungen für die Registrierung. Diese Berechtigungen entsprechen denen, die für den Aufruf von Exists und SourceExists erforderlich sind.

Beispiele
Im folgenden Beispiel wird eine Liste der Protokolle auf dem Computer "myServer" abgerufen. Anschließend wird der Name der einzelnen Protokolle ausgegeben.
Imports System
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
Dim remoteEventLogs() As EventLog
remoteEventLogs = EventLog.GetEventLogs("myServer")
Console.WriteLine(("Number of logs on computer: " & remoteEventLogs.Length))
Dim log As EventLog
For Each log In remoteEventLogs
Console.WriteLine(("Log: " & log.Log))
Next log
End Sub ' Main
End Class ' MySample
using System;
using System.Diagnostics;
using System.Threading;
class MySample{
public static void Main(){
EventLog[] remoteEventLogs;
remoteEventLogs = EventLog.GetEventLogs("myServer");
Console.WriteLine("Number of logs on computer: " + remoteEventLogs.Length);
foreach(EventLog log in remoteEventLogs){
Console.WriteLine("Log: " + log.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 );
}
}

Versionsinformationen
.NET FrameworkUnterstützt in: 4, 3.5, 3.0, 2.0, 1.1, 1.0 .NET Framework Client ProfileUnterstützt in: 4, 3.5 SP1

.NET Framework-Sicherheit

Plattformen
Windows 7, Windows Vista SP1 oder höher, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core wird nicht unterstützt), Windows Server 2008 R2 (Server Core wird mit SP1 oder höher unterstützt), Windows Server 2003 SP2
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.

Siehe auch
|