Hello everyone,
After some searched can not find the answers.
Suppose developing an Windows service application, and I need to register the event log in Windows registry.
1. What is the function of property EventMessageFile under SYSTEM\CurrentControlSet\Services\Eventlog\Application\[Some specific service name]?
2. How to fill the value for this property? I have analyzed a couple the values of property EventMessageFile of services of my local machine, and find all values for this property are different.
thanks in advance,
George
George GeorgePosted May 25, 2008, 5:52 AM
Thanks Scott,
Your code is great! My question is not about how to create event source and write event log in C# code. :-)
My question is how to create event log source in script, and I am writing an installation script for my C# Windows service application. I am studying the other Windows service applications' registry entries and find the similar items in Windows registry, but from search, I can not find any related help information about how to fill the entries. Do you have any ideas to my original question?
regards,
George
Scott LyslePosted May 25, 2008, 12:40 AM
It contains the message strings used to define the events. As far as writing to an event log, you do that using System.Diagnostics.EventLog:
public bool WriteToEventLog(
string entry,
string appName,
EventLogEntryType eventType,
string logName)
{
EventLog objEventLog = new EventLog();
try
{
//Register the Application as an Event Source
if (!EventLog.SourceExists(appName))
{
EventLog.CreateEventSource(appName, logName);
}
// log the entry
objEventLog.Source = appName;
objEventLog.WriteEntry(entry, eventType);
return true;
}
catch
{
return false;
}
}