Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clear all of the Event Logs in Windows?

How do I clear all of the Event Logs in Windows using C#?

like image 677
user1692494 Avatar asked Sep 27 '12 20:09

user1692494


People also ask

Can I delete Windows event logs?

Open Event Viewer and select the Windows log you wish to clear. Right-click on the log and select Clear Log. Select Save and Clear.

How do you clear an event?

Click on the Start button then type eventvwr. msc or Event Viewer. When you see the icon, right-click on it and select Run as Administrator to launch the Event Viewer. Finally, double-click on the folders in the left pane, right-click on the events you want to have deleted and then choose Clear Log.

What is the command used to clear the system logs in the Windows machine?

To clear the System log, use: 'wevtutil cl System' (without the quotes).


1 Answers

using System.Diagnostics;

using(var eventLog = new EventLog("Security", System.Environment.MachineName);
    eventLog.Clear();

to delete the security events logs.

to delete all:

foreach (var eventLog in EventLog.GetEventLogs())
{         
     eventLog.Clear();
     eventLog.Dispose();
}
like image 100
esskar Avatar answered Sep 22 '22 17:09

esskar