有没有办法写入这个事件日志:
或者至少,一些其他 Windows 默认日志,我不必在其中注册事件源?
最佳答案
是的,有一种方法可以写入您正在寻找的事件日志。您不需要创建新的源,只需使用现有的源,它通常与事件日志的名称同名,而且在某些情况下,例如事件日志应用程序,无需管理权限即可访问*。
*其他无法直接访问的情况,例如安全事件日志,它只能由操作系统访问。
我使用此代码直接写入事件日志应用程序:
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry("Log message example", EventLogEntryType.Information, 101, 1);
}
如您所见,EventLog 源与 EventLog 的名称相同。其原因可在 Event Sources @ Windows Dev Center 中找到。 (我将引用来源名称的部分加粗):
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.
关于c# - 在没有事件源注册的情况下写入 Windows 应用程序事件日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25725151/