NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

EventLog.Exists (String)

Determines whether the log exists on the local computer.

[Visual Basic]
Overloads Public Shared Function Exists( _
   ByVal logName As String _
) As Boolean
[C#]
public static bool Exists(
   string logName
);
[C++]
public: static bool Exists(
   String* logName
);
[JScript]
public static function Exists(
   logName : String
) : Boolean;

Parameters

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

Exceptions

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

Remarks

Use this overload 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.

This method looks in the registry; if you do not have the appropriate registry rights on the local computer, the query will return false.

Because a new log can't be given the name of an existing log on the same computer, use this method before creating a new log to determine if one with the specified logName already exists on the local computer. The logName parameter is not case sensitive.

Exists is a static (in Visual Basic Shared) method, so it can be called on the class itself. It is not necessary to instantiate EventLog to call Exists.

Example [Visual Basic]

The following example determines if the log "myLog" exists on the local computer. If it does, it is deleted.

Import the System.Diagnostics namespace for this example.

[Visual Basic]

Private Sub DeleteLog()
    'Declare an event log name
    Dim eventLogName As String
    eventLogName = "myLog"

    'If the event log passed in exists on the server, delete it.
    If EventLog.Exists(eventLogName) Then
        EventLog.Delete(eventLogName)
    End If
End Sub

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace | EventLog.Exists Overload List | CreateEventSource | Delete | SourceExists | Log