System.Diagnostics.EventLog.Delete Method

Removes an event log from the local computer.

Syntax

public static void Delete (string logName)

Parameters

logName
The name of the log to delete. Possible values include: Application, Security, System, and any custom event logs on the computer.

Remarks

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

EventLog.Delete(string) removes the log specified by logName from the local computer. If you want to delete only the source registered to a log, call EventLog.DeleteEventSource(string). If you only want to delete the log entries, call EventLog.Clear. EventLog.Delete(string) and EventLog.DeleteEventSource(string) are static methods, so they can be called on the class itself. It is not necessary to create a new instance of System.Diagnostics.EventLog to call either method.

The EventLog.Delete(string) method first deletes the file that holds the contents of the log. It then accesses the registry and removes all the event sources registered for that log. If you recreate the log at a later point, you should register the event sources again, if they are to be reused. If you do not register the event sources and other users write to an event source without specifying a log name, the event source will be created in the Application event log. Therefore, applications that previously were able to write entries to the log you deleted and recreated will write to the Application log instead, because it now contains the event source.

Note:

Recreating an event log can be a difficult process. Avoid deleting any of the system-created event logs, such as the Application log.

Deleting a log through a call to EventLog.Delete(string) automatically deletes the sources registered to that log. This can make other applications using that log inoperative.

Requirements

Namespace: System.Diagnostics
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0