即使将EventLog设置为另一个日志,它也会在Application中记录日志 [英] EventLog logs in Application, even though set to another log

查看:162
本文介绍了即使将EventLog设置为另一个日志,它也会在Application中记录日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用程序中创建了一个EventLog对象,该对象用于登录到自己的日志,如下所示:

I have created an EventLog object in my application, that I use to log to my own log, created like this:

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应用程序日志.我还必须说,该代码在我将另一个源注册到同一日志之前一直有效.该新"源可以正确记录日志.

When inspecting the eventLog object, it says the Log is set to "MyApplication". However, the logging always goes to the Windows Application log. I must also say that the code worked until I registered another source to the same log. That "new" source logs correctly.

更新:查看注册表时,正确创建了源(作为日志的子项)

Update When looking at the registry, the source is created correctly (as a subkey of the log)

有什么问题吗?

推荐答案

查看

Looking at EventLog.CreateEventSource is not creating a custom log, have you tried to restart your computer? It might be that the Event Log did not properly registered your source.

此外,请确保您以管理员身份运行该程序,否则它将无法正常工作.

Also, make sure that you are running the program as an administrator or it will not work.

这篇关于即使将EventLog设置为另一个日志,它也会在Application中记录日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆