我可以列出所有注册的事件源吗? [英] Can I list all registered event sources?
问题描述
我的Windows服务写入事件日志,但是在解决此问题时遇到了各种问题.因此,在此过程中,我使用了许多不同的名称.我跟随着一篇文章,描述了如何在Windows服务中设置事件日志.因此,在设计器中添加EventLog组件后,我将其添加到了构造函数中:
My windows service writes to the event log, but I've had various problems getting this correct. So in the process I used a number of different names. I followed an article describing how to set up event logs in windows services. So after adding an EventLog component in the designer, I have added this to the constructor:
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更改很多名称.
I found out that there is trouble if the source has the same name as the service name of the windows service. But I kept changing the names a lot for both the Log and the Source. The
EventLog[] eventLogs = EventLog.GetEventLogs();
列出事件日志,然后我可以删除那些不使用EventLog.Delete命令的事件日志.
Lists the eventlogs and I was able to remove those I didn't use with EventLog.Delete command.
但这如何工作?这些已删除的日志中是否仍存在注册源?我可以获取已注册来源的列表吗?
But how does this work? Are there still registered sources in these deleted logs? Can I get a list of registered sources?
推荐答案
由于所接受的答案丢失,因此这里是另一个.不幸的是,除了直接检查Windows注册表,我发现没有其他选择.
Since the accepted answer is lost, here is another. Unfortunately I found no alternative to examining the Windows Registry directly.
-
PowerShell (Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\<EventLogPathName>).pschildname
例如列出Windows 应用程序事件日志的来源:
E.g. to list the Windows Application Event Log's Sources:
-
PowerShell (Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\Application).pschildname
在阅读了多个资料后,我将其提出来.不幸的是,没有一个是非常明确或直接的.
I threw this up after reading several sources. Unfortunately none were very clear or direct.
这篇关于我可以列出所有注册的事件源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!