diff --git a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs index 50054f6501..d584666ab6 100644 --- a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs +++ b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs @@ -3644,6 +3644,7 @@ namespace System.Management.Automation internal static class MemberInvocationLoggingOps { +#if DEBUG private static readonly Lazy DumpLogAMSIContent = new Lazy( () => { object result = Environment.GetEnvironmentVariable("__PSDumpAMSILogContent"); @@ -3654,6 +3655,7 @@ namespace System.Management.Automation return false; } ); +#endif private static string ArgumentToString(object arg) { @@ -3708,20 +3710,24 @@ namespace System.Management.Automation string content = $"<{targetName}>.{name}({argsBuilder})"; +#if DEBUG if (DumpLogAMSIContent.Value) { Console.WriteLine("\n=== Amsi notification report content ==="); Console.WriteLine(content); } +#endif var success = AmsiUtils.ReportContent( name: contentName, content: content); +#if DEBUG if (DumpLogAMSIContent.Value) { Console.WriteLine($"=== Amsi notification report success: {success} ==="); } +#endif } catch (PSSecurityException) { @@ -3729,12 +3735,16 @@ namespace System.Management.Automation // must be propagated. throw; } +#pragma warning disable CS0168 // variable declared but never used catch (Exception ex) +#pragma warning restore CS0168 { +#if DEBUG if (DumpLogAMSIContent.Value) { Console.WriteLine($"!!! Amsi notification report exception: {ex} !!!"); } +#endif } } }