diff --git a/src/Tasks/Exec.cs b/src/Tasks/Exec.cs index fa6f346a5ec..f40e3ccd8df 100644 --- a/src/Tasks/Exec.cs +++ b/src/Tasks/Exec.cs @@ -336,6 +336,7 @@ protected override bool HandleTaskExecutionErrors() { if (IgnoreExitCode) { + // Don't log when EchoOff and IgnoreExitCode. if (!EchoOff) { Log.LogMessageFromResources(MessageImportance.Normal, "Exec.CommandFailedNoErrorCode", Command, ExitCode); @@ -343,16 +344,15 @@ protected override bool HandleTaskExecutionErrors() return true; } - if (!EchoOff) + // Don't emit expanded command when EchoOff is set. + string commandForLogging = EchoOff ? nameof(EchoOff) : Command; + if (ExitCode == NativeMethods.SE_ERR_ACCESSDENIED) { - if (ExitCode == NativeMethods.SE_ERR_ACCESSDENIED) - { - Log.LogErrorWithCodeFromResources("Exec.CommandFailedAccessDenied", Command, ExitCode); - } - else - { - Log.LogErrorWithCodeFromResources("Exec.CommandFailed", Command, ExitCode); - } + Log.LogErrorWithCodeFromResources("Exec.CommandFailedAccessDenied", commandForLogging, ExitCode); + } + else + { + Log.LogErrorWithCodeFromResources("Exec.CommandFailed", commandForLogging, ExitCode); } return false; }