19 : Exception(FormatMessage(process, includeOutputInMessage))
21 private static string FormatMessage(IProcess process,
bool includeOutputInMessage)
23 const string indentation =
" ";
25 var messageBuilder =
new StringBuilder()
26 .AppendLine($
"Process '{Path.GetFileName(process.FileName)}' exited with code {process.ExitCode}.")
27 .AppendLine($
"{indentation}> {process.FileName.DoubleQuoteIfNeeded()} {process.Arguments}")
28 .AppendLine($
"{indentation}@ {process.WorkingDirectory}");
30 if (includeOutputInMessage)
32 var errorOutput = process.Output.Where(x => x.Type == OutputType.Err).ToList();
33 if (errorOutput.Count > 0)
35 messageBuilder.AppendLine(
"Error output:");
36 errorOutput.ForEach(x => messageBuilder.Append(indentation).AppendLine(x.Text));
38 else if (Log.IsEnabled(LogEventLevel.Verbose))
40 messageBuilder.AppendLine(
"Standard output:");
41 process.Output.ForEach(x => messageBuilder.Append(indentation).AppendLine(x.Text));
45 return messageBuilder.ToString();
48 internal IProcess Process {
get; } = process;
50 public int ExitCode {
get; } = process.ExitCode;