I have tried with the following code to delete event log source. Referred with the document https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.delete?view=net-5.0
string applicationlog = "Application";
string mymachine = System.Environment.MachineName;
EventLog myapplicationLog = new EventLog(applicationlog,
mymachine);
EventLogEntryCollection entries =
myapplicationLog.Entries;
int LogCount = entries.Count;
if (LogCount <= 0)
{
_logger.LogInformation("No Event Logs in the Log :");
}
if (EventLog.SourceExists("test123"))
{
// Find the log associated with this source.
logName = EventLog.LogNameFromSourceName("test123", mymachine);
// Make sure the source is in the log we believe it to be in.
if (logName != "Application")
return;
// Delete the source and the log.
EventLog.DeleteEventSource("test123", mymachine);
EventLog.Delete(logName, mymachine);
_logger.LogInformation(logName + " deleted.");
}
When i executing the above code, all events deleted. i need to delete specifically. How to delete event log with specific id(EventRecordID)?