9

There are certain circumstances in our application where non-fatal errors occur and the application recovers.

An example of this failing to correctly identify some importable items when populating said items to a selection list. The errors won't crash the app but a user would be alerted that some of the items failed to load.

In this case, the error is logged to the Application event log as a warning. It's a non-fatal error that the app recovers from, but logging to the event log allows us to see the original error if need be.

Our problem is that the software needs to be able to be installed with a Power User account. Not being an admin account, we won't have the ability to create custom event sources for the application.

The aim is to write the errors instead to the "Application" event source (which already exists appears in the Application event log). Doing this, however, causes text similar to the following to also be included.

The description for Event ID 0 from source Application cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

This is because the EventID is 0 when we write it. This approach will get the job done, but is there a a better way? Is there a non-admin way to specify the EventID for the Application Event source to indicate that it came from our app?

MoSlo
  • 2,780
  • 4
  • 33
  • 37

2 Answers2

0

You are able to pass the Application Event ID as a parameter: ( example : 234 )

EventLog.WriteEntry("Application", "your log message here", EventLogEntryType.Warning,  234);

Further reading into EventLog.WriteEntry Method

http://msdn.microsoft.com/en-us/library/xzwc042w.aspx

  • 1
    Just for the sake of completeness, I would also edit in to add that it *is* OK to use the *Application* event source like this. (unless you disagree that it's OK, of course!) – Andrew Barber Nov 29 '12 at 11:46
  • "Application" in that example is the message, not the event source. The event source is "dotNET Sample App". public static void WriteEntry( string source, string message, EventLogEntryType type, int eventID ) – fsimonazzi Nov 29 '12 at 11:53
  • This is not answer the question. Also, this results in "The description for Event ID 234 from source Application cannot be found.." – user2864740 Jul 14 '16 at 06:30
0

The error you see as The description for Event ID 0 from source Application cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer. is the result of the Application source's registered event message file not having an entry for event id 0. The message you see is the result of getting the template for the message id from the event message file and formatting it with the event payload.

I would not recommend in general that you hijack a source you don't own. Whoever is consuming those events has specific expectations about what they mean and what information they carry.

Regarding Is there a non-admin way to specify the EventID for the Application Event source to indicate that it came from our app?, what do you expect that event id specification would mean? The source is what determines where the event came from.

EDIT:

You will get the error in event viewer regardless of whether you provide an event id other than 0, because that source does not have an event message file registered. And even if it did, you would either have to use event ids that have an entry in the message file (confusing the consumers of the events) or event ids that do not have an entry and still get the error.

fsimonazzi
  • 2,975
  • 15
  • 13
  • I've done some reading: the EventID combined with the Event Source identifies what kind of event is occurring. In short: I don't mind the warning error but I shouldnt be using a source that I didnt create. I'm not in a position to create one (non admin installation etc), so I'm hoping to find an event source that's available for these kinds of events or else use a different mechanism for logging. Thoughts? – MoSlo Nov 29 '12 at 12:59
  • If you're using .NET 4.5 you could use the EventSource class (http://msdn.microsoft.com/en-us/library/system.diagnostics.tracing.eventsource.aspx) to write events to ETW without requiring registration. The downside is that the events are not saved in the event log, so if you're not actively listening for those events you won't get them. – fsimonazzi Nov 29 '12 at 13:05