Export (0) Print
Expand All

How to: Delete Event Logs

You can delete any event log on your local computer or a remote server, provided you have the appropriate registry rights. When you delete a log, the system first deletes the file that contains the log's contents and then accesses the registry and removes the registration for all of the event sources that were registered for that log. Even if you re-create the log at a later point, this process will not create the sources by default, so some applications that previously were able to write entries to that log may not be able to write to the new log.

You must have registry rights on the computer on which you want to delete a log. For more information, see your Windows documentation.

NoteNote:

Re-creating an event log can be a difficult process. It is good practice to not delete any of the system-created event logs, such as the Application log. You can delete your custom logs and re-create them as needed.

To delete an event log

  • Call the Delete method and specify the name of the log you want to delete.

    System.Diagnostics.EventLog.Delete("MyCustomLog");
    
    NoteNote:

    Because the Delete method is static, you do not need to create an instance of the EventLog component before you call the method — instead, you can call the method on the EventLog class itself.

    TipTip:

    To delete an event log on a remote computer, specify the name of the computer as a second parameter.

    The following code shows an example of verifying a source and deleting a log if the source exists. This code assumes that an Imports or using statement exists for the System.Diagnostics namespace:

    if (System.Diagnostics.EventLog.Exists("MyCustomLog"))
    {
        System.Diagnostics.EventLog.Delete("MyCustomLog");
    }
    

Community Additions

ADD
Show:
© 2015 Microsoft