diff --git a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs index 00a392a2bec071..f4ef7e7467f4a5 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs @@ -412,7 +412,7 @@ private unsafe void DeferredContinue() catch (Exception e) { _status.currentState = ServiceControlStatus.STATE_PAUSED; - WriteLogEntry(SR.Format(SR.ContinueFailed, e), true); + WriteLogEntry(SR.Format(SR.ContinueFailed, e), EventLogEntryType.Error); // We re-throw the exception so that the advapi32 code can report // ERROR_EXCEPTION_IN_SERVICE as it would for native services. @@ -434,7 +434,7 @@ private void DeferredCustomCommand(int command) } catch (Exception e) { - WriteLogEntry(SR.Format(SR.CommandFailed, e), true); + WriteLogEntry(SR.Format(SR.CommandFailed, e), EventLogEntryType.Error); // We should re-throw the exception so that the advapi32 code can report // ERROR_EXCEPTION_IN_SERVICE as it would for native services. @@ -455,7 +455,7 @@ private unsafe void DeferredPause() catch (Exception e) { _status.currentState = ServiceControlStatus.STATE_RUNNING; - WriteLogEntry(SR.Format(SR.PauseFailed, e), true); + WriteLogEntry(SR.Format(SR.PauseFailed, e), EventLogEntryType.Error); // We re-throw the exception so that the advapi32 code can report // ERROR_EXCEPTION_IN_SERVICE as it would for native services. @@ -482,7 +482,7 @@ private void DeferredPowerEvent(int eventType, IntPtr eventData) } catch (Exception e) { - WriteLogEntry(SR.Format(SR.PowerEventFailed, e), true); + WriteLogEntry(SR.Format(SR.PowerEventFailed, e), EventLogEntryType.Error); // We rethrow the exception so that advapi32 code can report // ERROR_EXCEPTION_IN_SERVICE as it would for native services. @@ -498,7 +498,7 @@ private void DeferredSessionChange(int eventType, int sessionId) } catch (Exception e) { - WriteLogEntry(SR.Format(SR.SessionChangeFailed, e), true); + WriteLogEntry(SR.Format(SR.SessionChangeFailed, e), EventLogEntryType.Error); // We rethrow the exception so that advapi32 code can report // ERROR_EXCEPTION_IN_SERVICE as it would for native services. @@ -530,7 +530,7 @@ private unsafe void DeferredStop() { _status.currentState = previousState; SetServiceStatus(_statusHandle, pStatus); - WriteLogEntry(SR.Format(SR.StopFailed, e), true); + WriteLogEntry(SR.Format(SR.StopFailed, e), EventLogEntryType.Error); throw; } } @@ -556,7 +556,7 @@ private unsafe void DeferredShutdown() } catch (Exception e) { - WriteLogEntry(SR.Format(SR.ShutdownFailed, e), true); + WriteLogEntry(SR.Format(SR.ShutdownFailed, e), EventLogEntryType.Error); throw; } } @@ -641,7 +641,7 @@ public static unsafe void Run(ServiceBase[] services) service.Dispose(); if (!res) { - service.WriteLogEntry(SR.Format(SR.StartFailed, errorMessage), true); + service.WriteLogEntry(SR.Format(SR.StartFailed, errorMessage), EventLogEntryType.Error); } } } @@ -847,7 +847,7 @@ private void ServiceQueuedMainCallback(object state) } catch (Exception e) { - WriteLogEntry(SR.Format(SR.StartFailed, e), true); + WriteLogEntry(SR.Format(SR.StartFailed, e), EventLogEntryType.Error); _status.currentState = ServiceControlStatus.STATE_STOPPED; // We capture the exception so that it can be propagated @@ -900,7 +900,7 @@ public unsafe void ServiceMainCallback(int argCount, IntPtr argPointer) if (_statusHandle == (IntPtr)0) { string errorMessage = new Win32Exception().Message; - WriteLogEntry(SR.Format(SR.StartFailed, errorMessage), true); + WriteLogEntry(SR.Format(SR.StartFailed, errorMessage), EventLogEntryType.Error); } _status.controlsAccepted = _acceptedCommands; @@ -943,21 +943,21 @@ public unsafe void ServiceMainCallback(int argCount, IntPtr argPointer) statusOK = SetServiceStatus(_statusHandle, pStatus); if (!statusOK) { - WriteLogEntry(SR.Format(SR.StartFailed, new Win32Exception().Message), true); + WriteLogEntry(SR.Format(SR.StartFailed, new Win32Exception().Message), EventLogEntryType.Error); _status.currentState = ServiceControlStatus.STATE_STOPPED; SetServiceStatus(_statusHandle, pStatus); } } } - private void WriteLogEntry(string message, bool error = false) + private void WriteLogEntry(string message, EventLogEntryType type = EventLogEntryType.Information) { // EventLog failures shouldn't affect the service operation try { if (AutoLog) { - EventLog.WriteEntry(message); + EventLog.WriteEntry(message, type); } } catch