How do I clear all of the Event Logs in Windows using C#?
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.
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.
To clear the System log, use: 'wevtutil cl System' (without the quotes).
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With