我可以列出所有注册的活动来源吗?

我的Windows服务写入事件日志,但我遇到了各种问题,这是正确的。 所以在这个过程中我使用了许多不同的名字。 我跟着一篇文章描述了如何在Windows服务中设置事件日志。 因此,在设计器中添加EventLog组件后,我已将其添加到构造函数中:

if (!System.Diagnostics.EventLog.SourceExists("AS0604")) System.Diagnostics.EventLog.CreateEventSource("AS0604", "SIRR"); eventLog1.Source = "AS0604"; eventLog1.Log = "SIRR"; eventLog1.WriteEntry("AS is initializing...", EventLogEntryType.Information, 16); 

我发现,如果源名称与Windows服务的服务名称相同,则会出现问题。 但是我一直在为Log和Source更改名称。 该

 EventLog[] eventLogs = EventLog.GetEventLogs(); 

列出事件日志,我能够删除那些我没有使用EventLog.Delete命令。

但这是如何工作的? 这些已删除的日志中是否仍有已注册的来源? 我可以获得注册来源列表吗?

从它的一些好处来看,看起来答案是你无法从这个API获得一个源列表。 删除日志会删除在其中注册的源。

此页面告诉您如何使用直接注册表访问来执行此操作:

http://codeidol.com/csharp/csharpckbk2/Diagnostics/Finding-All-Sources-Belonging-to-a-Specific-Event-Log/

通过powershell:

 Get-EventLog -LogName Application |Select-Object Source -Unique 

请参阅: https : //social.technet.microsoft.com/Forums/windowsserver/en-US/48d1e34d-6ded-4039-a8a4-3b17d9c69488/list-eventlog-sources?forum=winserverpowershell