Search code examples
c#windowsevent-log

eventlog source - string/message table lookup failed


I am trying to write to the eventlog and although the message I enter is successfully added to the log, I get the following error:

the message resource is present but the message is not found in the string/message table

Noe, I know what this means, but I am wondering if someone can give me clear instructions as to how to add a custom message to the string/message table so I do not get this error for my custom error. I saw some stuff on C++ files that I think were explaining about this issue, but what I found was not step by step instructions, and as far as I could tell some important and necessary information could have been left out, so I thought coming here for a direct answer may be a better way to learn how to do this.

I am writing code in C# .Net to write an entry to the event log:

try 
{
     EventLog.WriteEntry("LogSource", "test", EventLogEntryType.Error);
}
catch
{
    Console.WriteLine("Could not write to log.");
}

Solution

  • Try to pass in an ID like this:

            try
            {
                EventLog.WriteEntry("LogSource", "test", EventLogEntryType.Error, 6285);
            }
            catch
            {
                MessageBox.Show("Could not write to log.");
            }
    

    Also, if you have a custom message file, try taking out the lines which say Severity= XXX and Facility=XXX.