Export (0) Print
Expand All

EventLog.Clear Method

Removes all entries from the event log.

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

public:
void Clear ()
public void Clear ()
public function Clear ()
Not applicable.

Exception typeCondition

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; make sure "mySource" is registered to a custom log before executing this sample code.

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


import System.*;
import System.Diagnostics.*;
import System.Threading.*;

class MySample
{
    public static void main(String[] args)
    {
        // Create an EventLog instance and assign its log name.
        EventLog myLog = new EventLog();
        myLog.set_Log("myNewLog");
        myLog.Clear();
    } //main
} //MySample

Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft