Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

EventLog.Clear Method

Removes all entries from the event log.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)

public void Clear()

ExceptionCondition
Win32Exception

The event log was not cleared successfully.

-or-

The log cannot be opened. A Windows error code is not available.

ArgumentException

A value is not specified for the Log property. Make sure the log name is not an empty string.

InvalidOperationException

The log does not exist.

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.

The following example clears an event log.

Caution noteCaution

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;
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();                                                                    
    }       
}
   

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft