EventLog.Clear Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Removes all entries from the event log.
public:
void Clear();
public void Clear ();
member this.Clear : unit -> unit
Public Sub Clear ()
The event log was not cleared successfully.
-or-
The log cannot be opened. A Windows error code is not available.
A value is not specified for the Log property. Make sure the log name is not an empty string.
The log does not exist.
The following example clears an event log.
Caution
Because Application, System, Security, and other non-custom logs can contain crucial information; be sure to specify a custom log before executing this example code. This example deletes the custom log myNewLog
.
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
// Create an EventLog instance and assign its log name.
EventLog^ myLog = gcnew EventLog;
myLog->Log = "myNewLog";
myLog->Clear();
}
using System;
using System.Diagnostics;
using System.Threading;
class MySample{
public static void Main(){
// Create an EventLog instance and assign its log name.
EventLog myLog = new EventLog();
myLog.Log = "myNewLog";
myLog.Clear();
}
}
Option Explicit
Option Strict
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
' Create an EventLog instance and assign its log name.
Dim myLog As New EventLog()
myLog.Log = "myNewLog"
myLog.Clear()
End Sub
End Class
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 or begins to overwrite earlier entries. If event recording stops, you can use this method to clear the log of existing entries and allow it to start recording events again. You must have administrator permissions to the computer on which the log resides to clear event log entries.
Clear closes the event log, releases the event handles, retrieves new read and write handles, and reopens the event log. Events received after the call to the method are not cleared along with the existing events.
Product | Versions |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: