Removes an event log from the local computer.
[Visual Basic] Overloads Public Shared Sub Delete( _ ByVal logName As String _ ) [C#] public static void Delete( string logName ); [C++] public: static void Delete( String* logName ); [JScript] public static function Delete( logName : String );
Exception Type | Condition |
---|---|
ArgumentException | The log name is a null reference (in Visual Basic Nothing) or is an empty string (""). |
SystemException | There is no 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 the local 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 local computer. 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 local computer. The example verifies whether "myLog" exists on the local 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" '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.Delete Overload List | Clear | Close | DeleteEventSource