Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

EventLog.Clear Method

Removes all entries from the event log.

[Visual Basic]
Public Sub Clear()
[C#]
public void Clear();
[C++]
public: void Clear();
[JScript]
public function Clear();

Exceptions

Exception Type Condition
Win32Exception The event log was not cleared successfully.

-or-

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

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.

Remarks

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 in order 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.

Example

[Visual Basic, C#, C++] The following example clears an event log.

[Visual Basic, C#, C++] CAUTION   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.
[Visual Basic] 
Option Explicit
Option Strict

Imports System
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 'Main
End Class 'MySample

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

[C++] 
#using <mscorlib.dll>
#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 = new EventLog();
    myLog->Log = S"myNewLog";

    myLog->Clear();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace | Close | Delete

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.