EventLog 记录在应用程序中,即使设置为另一个日志
EventLog logs in Application, even though set to another log
我在我的应用程序中创建了一个 EventLog
对象,我用它来记录我自己的日志,创建方式如下:
if (!System.Diagnostics.EventLog.SourceExists("MyApplication")) {
System.Diagnostics.EventLog.CreateEventSource(
"MySource", "MyApplication");
}
eventLog.Source = "MySource";
eventLog.Log = "MyApplication";
我这样记录条目:
eventLog.WriteEntry("some log line");
检查 eventLog
对象时,它说 Log
设置为 "MyApplication"
。但是,日志记录始终转到 Windows 应用程序日志。我还必须说,在我将另一个源注册到同一个日志之前,代码一直有效。 "new" 源记录正确。
更新 查看注册表时,源已正确创建(作为日志的子项)
有什么问题吗?
查看 EventLog.CreateEventSource is not creating a custom log,您是否尝试过重新启动计算机?可能是事件日志没有正确注册您的来源。
此外,需要创建源,请确保您是运行程序的管理员,否则将无法运行。
我在我的应用程序中创建了一个 EventLog
对象,我用它来记录我自己的日志,创建方式如下:
if (!System.Diagnostics.EventLog.SourceExists("MyApplication")) {
System.Diagnostics.EventLog.CreateEventSource(
"MySource", "MyApplication");
}
eventLog.Source = "MySource";
eventLog.Log = "MyApplication";
我这样记录条目:
eventLog.WriteEntry("some log line");
检查 eventLog
对象时,它说 Log
设置为 "MyApplication"
。但是,日志记录始终转到 Windows 应用程序日志。我还必须说,在我将另一个源注册到同一个日志之前,代码一直有效。 "new" 源记录正确。
更新 查看注册表时,源已正确创建(作为日志的子项)
有什么问题吗?
查看 EventLog.CreateEventSource is not creating a custom log,您是否尝试过重新启动计算机?可能是事件日志没有正确注册您的来源。
此外,需要创建源,请确保您是运行程序的管理员,否则将无法运行。