EventLog logs in Application, even though set to another log
Asked Answered
B

1

7

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?

Banjermasin answered 29/6, 2015 at 11:52 Comment(1)
What does you writes look like?Wrier
A
6

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 register your source.

Also, the source needs to be created, make sure that you are running the program as an administrator or it will not work.

Allfired answered 29/6, 2015 at 14:56 Comment(2)
That was it. I should have known, when it doesn't work, reboot. I am amazed how Microsoft manages to make something as simple as logging so complicated.Banjermasin
Had the same problem. The items logged appeared in the Windows Application log. Once computer restarted the items written before restart appeared in the correct log.Majoriemajority

© 2022 - 2024 — McMap. All rights reserved.