Reputation: 10022
Following this answer I made a very simple console application that writes something to the event viewer:
class Program
{
static void Main(string[] args)
{
for(int i=0;i<10000;i++)
{
Console.Write(".");
}
Console.WriteLine("Preparing to write into Event log");
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry("Log message example", EventLogEntryType.Information, 101, 1);
}
Console.WriteLine("I wrote to the event log. Press a key");
Console.ReadLine();
}
}
Then checking the event viewer, I do have an event that says "Log message example"! Yeahh!
However as part of the message I also got:(text translated by google)
Explanation of event ID 101 from source "Application" can not be found. The component that caused this event is not installed on the local computer or the installation is corrupted. Install the component on the local computer or repair the component.
If the event originates from another computer, you need to save the display information along with the event.
The event contains the following information:
Log message example
A message resource exists but a message could not be found in the message table.
What does this message mean?
My objective is just to write some message to the event viewer for later debug (obviously the above code is just a mock example, not the way I am going to finally use it)
Upvotes: 2
Views: 801
Reputation: 509
sounds like you're new to event logging. So let me explain how it works. To write to an event log, you need an Event Source. You cannot write to an event log without it. In this example, you have mentioned the source as Application and you don't have a custom event source for the console application you've designed. So windows will use the Application log.
Coming to your question, every event source should have an eventMessageFile attached to it, which gives an explanation of what the event is about. In your case, you don't have an eventMessageFile attached. Hence you get this error. Its safe to ignore this message for mock testing and add an eventMessageFile when you create an application.
An application can use the Application log without adding a new event source to the registry. However, because there are no message files, the Event Viewer cannot map any event identifiers or event categories to a description string, and will display an error. For this reason, you should add a unique event source to the registry for your application and specify a message file.
Sources:
Event Sources
EventMessageFile
Upvotes: 2