Removes an event log from the specified computer.
[Visual Basic] Overloads Public Shared Sub Delete( _ ByVal logName As String, _ ByVal machineName As String _ ) [C#] public static void Delete( string logName, string machineName ); [C++] public: static void Delete( String* logName, String* machineName ); [JScript] public static function Delete( logName : String, machineName : String );
Exception Type | Condition |
---|---|
ArgumentException | The computer name format is invalid. |
ArgumentException | The log name is a null reference (in Visual Basic Nothing) or is an empty string (""). |
SystemException | There is not an event log service or you don't have access to read the registry. |
SystemException | The log was not found. |
Use this method when the log you want to delete is on a remote computer. You can delete any log on the computer, provided you have the appropriate registry rights.
Delete removes the log specified by logName from the computer specifed by machineName. If you want to delete only the source registered to a log, call DeleteEventSource. If you only want to delete the log entries, call Clear. Delete and DeleteEventSource are static (in Visual Basic Shared) methods, so they can be called on the class itself. It is not necessary to instantiate EventLog to call either method.
This method first deletes the file holding the contents of the log. It then accesses the registry and removes all of the event sources that were registered for that log. Even if you re-create the log at a later point, you will not be able to re-register the event sources, so some applications that previously were able to write entries to that log will not be able to write to the new log.
Note Recreating an event log can be a difficult process. It is good practice to not delete any of the system-created event logs, such as the Application log.
The following example deletes a log from the computer "myComputer". The example verifies whether "myLog" exists on the computer before removing the log.
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.Delete Overload List | Clear