I have an application in production that has intermittent errors. I would like to add an error tracking feature so that, when an error gets channeled through the global handling routines, an entry gets written to the Event Log. I would like for this entry to use an event source unique to the application, to better track the errors.
So following Microsoft's own documentation, I tried this:
If Not EventLog.SourceExists("MyApp") Then<br /> EventLog.CreateEventSource("MyApp", "Application")<br /> End If<br /> MyLog.Source = "MyApp"<br /> MyLog.WriteEntry(DetailedMessage)<br />
Unfortunately,
EventLog.SourceExists
throws an exception: the Framework attempts to check
ALL of the logs, not just "Application", and Vista's psychotic paranoia does not allow the Framework to check the System log. So I tried always creating the source and ignoring the "source already exists" exception, like this:
Try<br /> EventLog.CreateEventSource("MyApp", "Application")<br /> Catch ex As Exception<br />
That throws the same exception about the System log, this time on
EventLog.CreateEventSource
. Attempting to write the entry therefore causes a "source does not exist" exception.
The solutions I have been able to find involve creating the event source manually, by writing the key to the registry. The key gets put in HKEY_LOCAL_MACHINE/System. Vista's "virtualization" has a firm lock on that node and redirects all programatic reads and writes to an isolated, user specific zone. This apparently rules out having the application create the source, as three different users will create three different logs, none of which will be visible to me when I log in as an administrator. And because this app runs on about 40 different machines, it is not feasable to go around to every one and configure the registry manually.
At this point, I see two options:
1. Roll my own event log. Write the errors out to an XML file and write a simple viewer to present the information.
2. Roll every workstation in the office back to XP because I am fed up with Vista.
Please, anyone, is it possible to use the event log under Vista? If so, HOW?