During some tests of a C# program that writes into the Event logs I accidentally created an event source "mysb" inside a event log named "mysb" instead of the "Application" event log.
Now I want to get rid of the mistakenly created event source but can't as it has the same name as the event log.
Is there any way to either eliminate source and event log mysb?
As it seems the names differ a bit (I took the names from how they are called from within C#): A source is ".Net Runtime", "Application Error", "Group Policy Files", ... While the protocol is "Application", "Security", ...
02 Answers
You can use the PowerShell command Remove-EventLog. According to the description on Microsoft docs:
The Remove-EventLog cmdlet deletes an event log file from a local or remote computer and unregisters all its event sources for the log. You can also use this cmdlet to unregister event sources without deleting any event logs.
(emphasis mine)
The syntax to remove an event log from the local computer is:
Remove-EventLog -LogName "MyLog"Note: You must run this from an elevated Command Prompt.
1As @memory-of-a-dream noticed in the comment, if a log file doesn't exist, Remove-EventLog gives an error and can't remove this log.
In this case, there are two options:
Option 1
- Create an empty file on the path where the log is supposed to be.
The path could be found in
eventvwr.msc. Right button on the problematic log, choose Properties - Restart Eventlog service. If it's not possible, restart the system
- Remove the log with
Remove-EventLog. Successfully this time
Option 2
Remove registry key which describes the broken log:
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\<Bad Log Name>"