Reputation: 11
In the project installer i am creating a custom event log. But when my service starts my all logs are going to the "Application" instead of my cuustom log. Below is the code which i have added to installer.
// Create Event Source and Event Log
EventLogInstaller logInstaller = new EventLogInstaller();
logInstaller.Source = "MyServices";
logInstaller.Log = "MyService Events";
Installers.Add(logInstaller);
Furthurmore the name of service is MyService.exe.
When I uninstall and re-install the service, i installation fail with the following install log;
Running a transacted installation.
Beginning the Install phase of the installation. See the contents of the log file for the D:\MyService\MyService\bin\Release\MyService.exe assembly's progress. The file is located at D:\MyService\MyService\bin\Release\MyService.InstallLog.
An exception occurred during the Install phase. System.ArgumentException: Source MyServices already exists on the local computer.
The Rollback phase of the installation is beginning. See the contents of the log file for the D:\MyService\MyService\bin\Release\MyService.exe assembly's progress. The file is located at D:\MyService\MyService\bin\Release\MyService.InstallLog.
The Rollback phase completed successfully.
The transacted install has completed.
And this is how i write log entry;
EventLog.WriteEntry("MyServices", logMessage, logType);
Can someone please help me what wrong i am doing.
Upvotes: 0
Views: 2687
Reputation: 351
I had a similar problem and solved it by:
Upvotes: 1
Reputation: 159
Need to create a EventSource in this way:
if (!EventLog.SourceExists(source))
{
var eventSourceData = new EventSourceCreationData(source, logName);
EventLog.CreateEventSource(eventSourceData);
}
source - "MyServices"
logName - some of your program name.
Insert the data need in this way:
log = new EventLog();
log.Source = "MyServices";
log.WriteEntry(message, entryType);
Upvotes: 0