Determines whether the log exists on the specified computer.
[Visual Basic] Overloads Public Shared Function Exists( _ ByVal logName As String, _ ByVal machineName As String _ ) As Boolean [C#] public static bool Exists( string logName, string machineName ); [C++] public: static bool Exists( String* logName, String* machineName ); [JScript] public static function Exists( logName : String, machineName : String ) : Boolean;
true if the log exists on the specified computer; otherwise, false.
Exception Type | Condition |
---|---|
ArgumentException | The machineName parameter is in an invalid format. Make sure you have used proper syntax for the computer on which you are searching.
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 a remote computer. If you want to determine whether a source exists on a remote 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 server specified by the machineName parameter. The logName and machineName parameters are 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 computer "myComputer". 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" Dim computer As String computer = "myComputer" 'If the event log passed in exists on the server, delete it. If EventLog.Exists(eventLogName, computer) Then EventLog.Delete(eventLogName, computer) End If End Sub
EventLog Class | EventLog Members | System.Diagnostics Namespace | EventLog.Exists Overload List | CreateEventSource | Delete | SourceExists | Log | MachineName