From ae60bde4278d78505edacf3b879107b598c61eab Mon Sep 17 00:00:00 2001 From: Adam Thorn <alt36@cam.ac.uk> Date: Wed, 10 Jun 2020 17:05:41 +0100 Subject: [PATCH] Fix eventlog source name By default, an eventsource of WpkgInstaller gets created in the Application log. We have to use a different eventsource name. --- WpkgInstaller/WpkgInstaller.Designer.cs | 1 - WpkgInstaller/WpkgInstaller.cs | 24 +++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/WpkgInstaller/WpkgInstaller.Designer.cs b/WpkgInstaller/WpkgInstaller.Designer.cs index 488aabd..4a43dca 100755 --- a/WpkgInstaller/WpkgInstaller.Designer.cs +++ b/WpkgInstaller/WpkgInstaller.Designer.cs @@ -33,7 +33,6 @@ // // eventLog // - this.eventLog.MachineName = ".eventLog"; this.eventLog.EntryWritten += new System.Diagnostics.EntryWrittenEventHandler(this.eventLog_EntryWritten); // // WpkgInstaller diff --git a/WpkgInstaller/WpkgInstaller.cs b/WpkgInstaller/WpkgInstaller.cs index 3189175..cf38bd4 100755 --- a/WpkgInstaller/WpkgInstaller.cs +++ b/WpkgInstaller/WpkgInstaller.cs @@ -1,5 +1,7 @@ using System.Runtime.InteropServices; using System.ServiceProcess; +using System.Diagnostics; +using System; namespace WpkgInstaller { @@ -33,17 +35,24 @@ namespace WpkgInstaller public WpkgInstaller() { InitializeComponent(); - if (!System.Diagnostics.EventLog.SourceExists("WpkgInstaller")) + + eventLog = new EventLog(); + string eventSourceName = "WpkgInstaller Service"; + string logName = "WpkgNotifier"; + + if (!EventLog.SourceExists(eventSourceName)) { - System.Diagnostics.EventLog.CreateEventSource( - "WpkgInstaller", "WpkgNotifier"); + EventLog.CreateEventSource(eventSourceName, logName); } - eventLog.Source = "WpkgNotifier"; - eventLog.Log = "WpkgInstaller"; + + eventLog.Source = eventSourceName; + eventLog.Log = logName; + } protected override void OnStart(string[] args) { + ServiceStatus serviceStatus = new ServiceStatus(); serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING; serviceStatus.dwWaitHint = 100000; @@ -52,7 +61,7 @@ namespace WpkgInstaller serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING; SetServiceStatus(this.ServiceHandle, ref serviceStatus); - eventLog.WriteEntry("Service started"); + eventLog.WriteEntry("Service started", EventLogEntryType.Information); } protected override void OnStop() @@ -65,12 +74,13 @@ namespace WpkgInstaller serviceStatus.dwCurrentState = ServiceState.SERVICE_STOPPED; SetServiceStatus(this.ServiceHandle, ref serviceStatus); - eventLog.WriteEntry("Service stopped"); + eventLog.WriteEntry("Service stopped", EventLogEntryType.Information); } private void eventLog_EntryWritten(object sender, System.Diagnostics.EntryWrittenEventArgs e) { } + } } -- GitLab