From 6ec255e2d5de19ffd15f88129c8341ccc89710af Mon Sep 17 00:00:00 2001 From: Luke Butters Date: Mon, 28 Oct 2024 10:33:36 +1100 Subject: [PATCH] When we can't write script outout to the script log, log to serilog --- .../Octopus.Tentacle/Scripts/RunningScript.cs | 19 ++++++++++++++++--- source/Tentacle.sln.DotSettings | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/source/Octopus.Tentacle/Scripts/RunningScript.cs b/source/Octopus.Tentacle/Scripts/RunningScript.cs index 40b501763..a55a61cbb 100644 --- a/source/Octopus.Tentacle/Scripts/RunningScript.cs +++ b/source/Octopus.Tentacle/Scripts/RunningScript.cs @@ -164,9 +164,9 @@ int RunScript(string shellPath, IScriptLogWriter writer) shellPath, shell.FormatCommandArguments(workspace.BootstrapScriptFilePath, workspace.ScriptArguments, false), workspace.WorkingDirectory, - output => writer.WriteOutput(ProcessOutputSource.Debug, output), - output => writer.WriteOutput(ProcessOutputSource.StdOut, output), - output => writer.WriteOutput(ProcessOutputSource.StdErr, output), + LogScriptOutputTo(writer, ProcessOutputSource.Debug), + LogScriptOutputTo(writer, ProcessOutputSource.StdOut), + LogScriptOutputTo(writer, ProcessOutputSource.StdErr), token); return exitCode; @@ -179,5 +179,18 @@ int RunScript(string shellPath, IScriptLogWriter writer) return ScriptExitCodes.PowershellInvocationErrorExitCode; } } + + Action LogScriptOutputTo(IScriptLogWriter logOutput, ProcessOutputSource level) + { + try + { + return output => logOutput.WriteOutput(level, output); + } + catch (Exception e) + { + log.Warn(e, $"Could not write script output to log, for task {taskId}"); + throw; + } + } } } \ No newline at end of file diff --git a/source/Tentacle.sln.DotSettings b/source/Tentacle.sln.DotSettings index 0e7802a6d..2c88b318a 100644 --- a/source/Tentacle.sln.DotSettings +++ b/source/Tentacle.sln.DotSettings @@ -183,6 +183,7 @@ True True True + True True True True