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;
true if the log exists on the local computer; otherwise, false.
Exception Type | Condition |
---|---|
ArgumentException | The logName is a null reference (in Visual Basic Nothing) or the value is empty. |
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.
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
EventLog Class | EventLog Members | System.Diagnostics Namespace | EventLog.Exists Overload List | CreateEventSource | Delete | SourceExists | Log