Clears the event log by removing all entries from it.
[Visual Basic] Overridable Public Sub Clear() [C#] public virtual void Clear(); [C++] public: virtual void Clear(); [JScript] public function Clear();
Exception Type | Condition |
---|---|
Win32Exception | The event log was not cleared successfully. |
ArgumentException | A value is not specified for the Log property. Make sure the log name is not an empty string. |
Exception | The log cannot be opened. No Windows error code is available. |
Win32Exception | The log cannot be opened. A Windows error code is available. |
Event logs are set with a maximum size that determines how many entries they can contain. When an event log is full, it stops recording new event information. You can clear the log of its existing entries to free the log and allow it to start recording events again. You must have administrator rights to the computer on which the log resides in order to clear event log entries.
Clear closes the event log and releases the event handles, retrieves new read and write handles, and opens the event log back into the previous state. Events that are received after the call to the method will not be cleared along with the existing events.
The following example clears an event log.
This example assumes that there is a Source on the local computer named "mySource".
Import the System.Diagnostics namespace for this example.
CAUTION Because Application, System, Security, and other non-custom logs can contain crucial information, make sure "mySource" registered to a custom log before executing this sample code.
[Visual Basic]
Private Sub ClearLog() Dim evtLog As EventLog evtLog = New EventLog Dim eventSource As String eventSource = "mySource" 'Check that the source exists for the log. If EventLog.SourceExists(eventSource) Then 'Connect the eventSource parameter to the event log. evtLog.Source = eventSource 'Clear the log. evtLog.Clear() End If End Sub
EventLog Class | EventLog Members | System.Diagnostics Namespace | Close | Delete