Selaa lähdekoodia

Merge pull request #165 from oleg-nenashev/bug/Issue164_UninstallLogging

Issue #146 - Improve logging of the Uninstall Operation.
Oleg Nenashev 8 vuotta sitten
vanhempi
sitoutus
099c41f19d
1 muutettua tiedostoa jossa 19 lisäystä ja 1 poistoa
  1. 19 1
      src/Core/ServiceWrapper/Main.cs

+ 19 - 1
src/Core/ServiceWrapper/Main.cs

@@ -644,11 +644,19 @@ namespace winsw
                 }
                 if (args[0] == "uninstall")
                 {
+                    Log.Info("Uninstalling the service with id '" + d.Id + "'");
                     if (s == null)
                     {
-                        Console.WriteLine("Warning! The service with id '" + d.Id + "' does not exist. Nothing to uninstall");
+                        Log.Warn("The service with id '" + d.Id + "' does not exist. Nothing to uninstall");
                         return; // there's no such service, so consider it already uninstalled
                     }
+                    if (s.Started)
+                    {
+                        // We could fail the opeartion here, but it would be an incompatible change.
+                        // So it is just a warning
+                        Log.Warn("The service with id '" + d.Id + "' is running. It may be impossible to uninstall it");
+                    }
+
                     try
                     {
                         s.Delete();
@@ -656,7 +664,17 @@ namespace winsw
                     catch (WmiException e)
                     {
                         if (e.ErrorCode == ReturnValue.ServiceMarkedForDeletion)
+                        {
+                            Log.Error("Failed to uninstall the service with id '" + d.Id + "'" 
+                               + ". It has been marked for deletion.");
+                            
+                            // TODO: change the default behavior to Error?
                             return; // it's already uninstalled, so consider it a success
+                        }
+                        else
+                        {
+                            Log.Fatal("Failed to uninstall the service with id '" + d.Id + "'. WMI Error code is '" + e.ErrorCode + "'");
+                        }
                         throw e;
                     }
                     return;