Disable AMSI content logging in release (#26235)

This commit is contained in:
xtqqczze
2025-12-03 13:16:56 +05:00
committed by GitHub
parent ef0f9ae0ba
commit 11f91dfee3
@@ -3644,6 +3644,7 @@ namespace System.Management.Automation
internal static class MemberInvocationLoggingOps
{
#if DEBUG
private static readonly Lazy<bool> DumpLogAMSIContent = new Lazy<bool>(
() => {
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
}
}
}