EventLog logs in Application, even though set to another log

血红的双手。 提交于 2019-12-10 16:33:39

问题


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";

I log entries like this:

eventLog.WriteEntry("some log line");

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)

What could be wrong?


回答1:


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.



来源:https://stackoverflow.com/questions/31114998/eventlog-logs-in-application-even-though-set-to-another-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!