DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore
Results found: 

Question

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 />            'Do nothing<br />        End Try<br />        MyLog.Source = "MyApp"<br />        MyLog.WriteEntry(TextBox1.Text.Trim)<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?

Solution

Just like writing to the HKLM section of the registry, creating an
event source requires elevated privileges. And also just like writing to
HKLM in the registry, apps that runs without elevation need to do these operations
at install time (which is why many installers give you a UAC prompt).

From the EventLog class docs:
"If you write to an event log, you must specify or create an event Source.
You must have administrative rights on the computer to create a new event source.
"


TechBearSeattle wrote:
Please, anyone, is it possible to use the event log under Vista? If so, HOW?


Yes. Provide some way to create the event source. Once the source is
registered, no elevation will be required for the app to write to the
event log.

If you like, leave us your opinion

Was the article helpful and is it translated correctly?

Licensed under: CC-BY-SA with attribution
Not affiliated with codeproject.com