Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing wrapper logs #485

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions src/WinSW/WrapperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ private void HandleFileCopies()
string? line;
while ((line = tr.ReadLine()) != null)
{
this.LogEvent("Handling copy: " + line);
this.LogInfo("Handling copy: " + line);
string[] tokens = line.Split('>');
if (tokens.Length > 2)
{
this.LogEvent("Too many delimiters in " + line);
Log.Error("Too many delimiters in " + line);
continue;
}

Expand All @@ -119,7 +119,7 @@ private void MoveFile(string sourceFileName, string destFileName)
}
catch (IOException e)
{
this.LogEvent("Failed to move :" + sourceFileName + " to " + destFileName + " because " + e.Message);
Log.Error("Failed to move :" + sourceFileName + " to " + destFileName + " because " + e.Message);
}
}

Expand Down Expand Up @@ -179,6 +179,12 @@ public void LogEvent(string message, EventLogEntryType type)
}
}

private void LogInfo(string message)
{
this.LogEvent(message);
Log.Info(message);
}

protected override void OnStart(string[] args)
{
this.envs = this.descriptor.EnvironmentVariables;
Expand All @@ -192,8 +198,7 @@ protected override void OnStart(string[] args)
{
Download download = downloads[i];
string downloadMessage = $"Downloading: {download.From} to {download.To}. failOnError={download.FailOnError.ToString()}";
this.LogEvent(downloadMessage);
Log.Info(downloadMessage);
this.LogInfo(downloadMessage);
tasks[i] = download.PerformAsync();
}

Expand All @@ -211,7 +216,6 @@ protected override void OnStart(string[] args)
Download download = downloads[i];
string errorMessage = $"Failed to download {download.From} to {download.To}";
AggregateException exception = tasks[i].Exception!;
this.LogEvent($"{errorMessage}. {exception.Message}");
Log.Error(errorMessage, exception);

// TODO: move this code into the download logic
Expand All @@ -232,7 +236,7 @@ protected override void OnStart(string[] args)
{
using Process process = this.StartProcess(prestartExecutable, this.descriptor.PrestartArguments);
this.WaitForProcessToExit(process);
Log.Info($"Pre-start process '{GetDisplayName(process)}' exited with code {process.ExitCode}.");
this.LogInfo($"Pre-start process '{GetDisplayName(process)}' exited with code {process.ExitCode}.");
}
}
catch (Exception e)
Expand All @@ -256,8 +260,7 @@ protected override void OnStart(string[] args)
// in the xml for readability.
startArguments = Regex.Replace(startArguments, @"\s*[\n\r]+\s*", " ");

this.LogEvent("Starting " + this.descriptor.Executable + ' ' + startArguments);
Log.Info("Starting " + this.descriptor.Executable + ' ' + startArguments);
this.LogInfo("Starting " + this.descriptor.Executable + ' ' + startArguments);

// Load and start extensions
this.ExtensionManager.LoadExtensions();
Expand All @@ -278,7 +281,7 @@ protected override void OnStart(string[] args)
process.Exited += (sender, _) =>
{
Process process = (Process)sender!;
Log.Info($"Post-start process '{GetDisplayName(process)}' exited with code {process.ExitCode}.");
this.LogInfo($"Post-start process '{GetDisplayName(process)}' exited with code {process.ExitCode}.");
};

process.EnableRaisingEvents = true;
Expand Down Expand Up @@ -335,7 +338,7 @@ private void StopIt()
{
using Process process = this.StartProcess(prestopExecutable, this.descriptor.PrestopArguments);
this.WaitForProcessToExit(process);
Log.Info($"Pre-stop process '{GetDisplayName(process)}' exited with code {process.ExitCode}.");
this.LogInfo($"Pre-stop process '{GetDisplayName(process)}' exited with code {process.ExitCode}.");
}
}
catch (Exception e)
Expand All @@ -344,8 +347,7 @@ private void StopIt()
}

string? stopArguments = this.descriptor.StopArguments;
this.LogEvent("Stopping " + this.descriptor.Id);
Log.Info("Stopping " + this.descriptor.Id);
this.LogInfo("Stopping " + this.descriptor.Id);
this.orderlyShutdown = true;
this.process.EnableRaisingEvents = false;

Expand Down Expand Up @@ -381,7 +383,7 @@ private void StopIt()
{
using Process process = this.StartProcess(poststopExecutable, this.descriptor.PoststopArguments);
this.WaitForProcessToExit(process);
Log.Info($"Post-stop process '{GetDisplayName(process)}' exited with code {process.ExitCode}.");
this.LogInfo($"Post-stop process '{GetDisplayName(process)}' exited with code {process.ExitCode}.");
}
}
catch (Exception e)
Expand Down Expand Up @@ -437,11 +439,11 @@ void OnProcessCompleted(Process process)

if (this.orderlyShutdown)
{
this.LogEvent("Child process [" + msg + "] terminated with " + process.ExitCode, EventLogEntryType.Information);
this.LogInfo("Child process [" + msg + "] terminated with " + process.ExitCode);
}
else
{
this.LogEvent("Child process [" + msg + "] finished with " + process.ExitCode, EventLogEntryType.Warning);
Log.Warn("Child process [" + msg + "] finished with " + process.ExitCode);

// if we finished orderly, report that to SCM.
// by not reporting unclean shutdown, we let Windows SCM to decide if it wants to
Expand Down