EventLog.Exists Method (String)

Determines whether the log exists on the local computer.

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

Public Shared Function Exists ( _
	logName As String _
) As Boolean
Dim logName As String
Dim returnValue As Boolean

returnValue = EventLog.Exists(logName)
public static boolean Exists (
	String logName
public static function Exists (
	logName : String
) : boolean



The name of the log to search for. Possible values include: Application, Security, System, other application-specific logs (such as those associated with Active Directory), or any custom log on the computer.

Return Value

true if the log exists on the local computer; otherwise, false.

Exception typeCondition


The logName is a null reference (Nothing in Visual Basic) or the value is empty.

Use this method to determine if a log exists on the local computer. If you want to determine whether a source exists on the local computer, use SourceExists.

Because this method accesses the registry, you must have the appropriate registry permissions on the local computer; otherwise, the query returns false.

Because you cannot give a new log the name of an existing log on the same computer, use this method before creating a new log to determine if the specified logName already exists on the local computer. The logName parameter is not case sensitive.

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

Dim myLog As String = "myNewLog"
If EventLog.Exists(myLog) Then
   Console.WriteLine("Log '" + myLog + "' exists.")
   Console.WriteLine("Log '" + myLog + "' does not exist.")
End If

String myLog = "myNewLog";
if (EventLog.Exists(myLog)) {
    Console.WriteLine("Log '" + myLog + "' exists.");
else {
    Console.WriteLine("Log '" + myLog + "' does not exist.");

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