有没有办法写入这个事件日志:
或者至少是其他一些 Windows 默认日志,我不必在其中注册事件源?
解决方案是的,有一种方法可以写入您要查找的事件日志.您无需创建新源,只需使用现有源,该源通常与 EventLog 的名称相同,并且在某些情况下,例如事件日志应用程序,无需管理权限即可访问*.
*其他无法直接访问的情况,例如安全事件日志,只能由操作系统访问.
我使用此代码直接写入事件日志应用程序:
using (EventLog eventLog = new EventLog("Application")){eventLog.Source = "应用程序";eventLog.WriteEntry("日志消息示例", EventLogEntryType.Information, 101, 1);}如您所见,EventLog 源与 EventLog 的名称相同.原因可以在 Event Sources @ Windows 中找到开发中心(我将引用源名称的部分加粗):
Eventlog 键中的每个日志都包含称为事件源的子键.事件源是记录事件的软件的名称.通常是应用程序的名称,如果应用程序很大,则是应用程序的子组件的名称.您最多可以向注册表添加 16,384 个事件源.
Is there a way to write to this event log:
Or at least, some other Windows default log, where I don't have to register an event source?
解决方案Yes, there is a way to write to the event log you are looking for. You don't need to create a new source, just simply use the existent one, which often has the same name as the EventLog's name and also, in some cases like the event log Application, can be accessible without administrative privileges*.
*Other cases, where you cannot access it directly, are the Security EventLog, for example, which is only accessed by the operating system.
I used this code to write directly to the event log Application:
using (EventLog eventLog = new EventLog("Application")) { eventLog.Source = "Application"; eventLog.WriteEntry("Log message example", EventLogEntryType.Information, 101, 1); }As you can see, the EventLog source is the same as the EventLog's name. The reason of this can be found in Event Sources @ Windows Dev Center (I bolded the part which refers to source name):
Each log in the Eventlog key contains subkeys called event sources. The event source is the name of the software that logs the event. It is often the name of the application or the name of a subcomponent of the application if the application is large. You can add a maximum of 16,384 event sources to the registry.
更多推荐
写入 Windows 应用程序事件日志
发布评论