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.Delete Method (String)

Removes an event log from the local computer.

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

public static void Delete (
	string logName
)
public static void Delete (
	String logName
)
public static function Delete (
	logName : String
)
Not applicable.

Parameters

logName

The name of the log to delete. Possible values include: Application, Security, System, and any custom event logs on the computer.

Exception typeCondition

ArgumentException

logName is an empty string ("") or a null reference (Nothing in Visual Basic).

InvalidOperationException

The registry key for the event log could not be opened on the local computer.

- or -

The log does not exist on the local computer.

Win32Exception

The event log was not cleared successfully.

-or-

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

Use this method when the log you want to delete is on the local computer. You can delete any log on the computer, provided you have the appropriate registry permissions.

Delete removes the log specified by logName from the local computer. If you want to delete only the source registered to a log, call DeleteEventSource. If you only want to delete the log entries, call Clear. Delete and DeleteEventSource are static methods, so they can be called on the class itself. It is not necessary to create a new instance of EventLog to call either method.

This method first deletes the file holding the contents of the log. It then accesses the registry and removes all the event sources registered for that log. Even if you recreate the log at a later point, you will not be able to register the event sources again. Therefore, applications that previously were able to write entries to that log using the specified source will not be able to write to the new log.

NoteNote:

Recreating an event log can be a difficult process. Avoid deleting any of the system-created event logs, such as the Application log.

Deleting a log through a call to Delete automatically deletes the sources registered to that log. This can make other applications using that log inoperative.

The following example deletes a log from the local computer. The example determines the log from its source.

NoteNote:

More than one source might write to an event log. Before deleting a custom log, make sure there are no other sources writing to that log.

using System;
using System.Diagnostics;
using System.Threading;
              
class MySample{

    public static void Main(){

         string logName;
       
        if(EventLog.SourceExists("MyOldSource")){
        // Find the log associated with this source.    
            logName = EventLog.LogNameFromSourceName("MyOldSource", ".");

        // Delete the source and the log.
            EventLog.DeleteEventSource("MyOldSource");
            EventLog.Delete(logName);
            
            Console.WriteLine(logName + " deleted.");    
        }                                                                        
    } 
}
   

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

class MySample
{
    public static void main(String[] args)
    {
        String logName;
        if (EventLog.SourceExists("MyOldSource")) {
            // Find the log associated with this source.    
            logName = EventLog.LogNameFromSourceName("MyOldSource", ".");

            // Delete the source and the log.
            EventLog.DeleteEventSource("MyOldSource");
            EventLog.Delete(logName);
            Console.WriteLine(logName + " deleted.");
        }
    } //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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft