Skip to content

Reduce CLI diagnostic log noise and improve process logging#15956

Open
JamesNK wants to merge 2 commits intomainfrom
jamesn/diskcache-reduce-log-level
Open

Reduce CLI diagnostic log noise and improve process logging#15956
JamesNK wants to merge 2 commits intomainfrom
jamesn/diskcache-reduce-log-level

Conversation

@JamesNK
Copy link
Copy Markdown
Member

@JamesNK JamesNK commented Apr 8, 2026

Description

Reduces diagnostic log noise in the Aspire CLI and improves process execution logging clarity.

Changes:

  • ProcessExecution/ProcessExecutionFactory: Instead of checking SuppressLogging at every log call site, the factory now passes NullLogger.Instance when logging is suppressed. This simplifies ProcessExecution by removing all conditional logging branches.
  • Process log messages improved: Include both file name and working directory for better diagnostics.
  • Features: Downgraded "using default value" log from Debug to Trace to reduce noise. Added LogFeatureState() method that logs all feature flag states at startup.
  • Program.cs: Calls LogFeatureState() at startup so feature configuration is visible in diagnostic logs.
  • NuGetPackageCache / BundleNuGetPackageCache: Hoisted IsFeatureEnabled call out of the per-package filter lambda to avoid redundant evaluations.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

Copilot AI review requested due to automatic review settings April 8, 2026 07:35
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15956

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15956"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces diagnostic log noise in the Aspire CLI while improving the clarity and consistency of process execution logging. It also adds a startup log of all known feature flag states and avoids redundant feature-flag evaluation in NuGet package filtering.

Changes:

  • Centralize “suppress logging” behavior in ProcessExecutionFactory by using NullLogger and simplify ProcessExecution logging branches.
  • Add IFeatures.LogFeatureState() and call it at CLI startup to emit feature flag state for diagnostics.
  • Reduce log verbosity for cache/feature default behavior and avoid repeated IsFeatureEnabled calls inside per-package filter lambdas.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Aspire.Cli/Program.cs Calls LogFeatureState() during startup to surface feature configuration in logs.
src/Aspire.Cli/NuGet/NuGetPackageCache.cs Hoists ShowDeprecatedPackages evaluation outside the per-package filter lambda.
src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs Hoists ShowDeprecatedPackages evaluation outside the per-package filter lambda.
src/Aspire.Cli/DotNet/ProcessExecutionFactory.cs Uses NullLogger when suppressed and improves “running process” log context.
src/Aspire.Cli/DotNet/ProcessExecution.cs Removes per-callsite suppression checks; adjusts process start/wait and stream forwarding logging.
src/Aspire.Cli/Configuration/IFeatures.cs Adds new LogFeatureState() API to the internal feature service contract.
src/Aspire.Cli/Configuration/Features.cs Downgrades default-value log to Trace and implements LogFeatureState().
src/Aspire.Cli/Caching/DiskCache.cs Downgrades cache hit/miss/store/delete logs from Debug to Trace.

Comment on lines +31 to +37
public void LogFeatureState()
{
foreach (var metadata in KnownFeatures.GetAllFeatureMetadata())
{
var value = IsFeatureEnabled(metadata.Name, metadata.DefaultValue);
logger.LogDebug("Feature {Feature} = {Value} (default: {DefaultValue})", metadata.Name, value, metadata.DefaultValue);
}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Features.LogFeatureState() references KnownFeatures, but KnownFeatures is declared in the Aspire.Cli namespace (src/Aspire.Cli/KnownFeatures.cs). This file is in Aspire.Cli.Configuration and currently lacks a using/fully-qualified reference, so this will not compile. Add using Aspire.Cli; (or fully-qualify Aspire.Cli.KnownFeatures).

Copilot uses AI. Check for mistakes.
internal interface IFeatures
{
bool IsFeatureEnabled(string featureFlag, bool defaultValue);
void LogFeatureState();
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding LogFeatureState() to IFeatures is a breaking change for all IFeatures implementations (including numerous test fakes in tests/Aspire.Cli.Tests) and will cause compilation failures until they implement the new member. Consider either updating those implementations in this PR, or making this a non-interface extension method/default interface implementation to avoid widespread breakage.

Suggested change
void LogFeatureState();
void LogFeatureState() { }

Copilot uses AI. Check for mistakes.
Comment on lines +18 to 28
var effectiveLogger = options.SuppressLogging ? (ILogger)NullLogger.Instance : logger;

if (!suppressLogging)
{
logger.LogDebug("Running {FullName} with args: {Args}", workingDirectory.FullName, string.Join(" ", args));
effectiveLogger.LogDebug("Running {FileName} in {WorkingDirectory} with args: {Args}", fileName, workingDirectory.FullName, string.Join(" ", args));

if (env is not null)
if (env is not null)
{
foreach (var envKvp in env)
{
foreach (var envKvp in env)
{
logger.LogDebug("Running {FullName} with env: {EnvKey}={EnvValue}", workingDirectory.FullName, envKvp.Key, envKvp.Value);
}
effectiveLogger.LogDebug("{FileName} env: {EnvKey}={EnvValue}", fileName, envKvp.Key, envKvp.Value);
}
}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the NullLogger approach, expensive argument formatting and env enumeration still happens when logging is suppressed because string.Join and the env foreach run unconditionally. Guard these with effectiveLogger.IsEnabled(LogLevel.Debug) (and only build the args string / iterate env when enabled) so SuppressLogging avoids the work as well as the output.

Copilot uses AI. Check for mistakes.
Comment on lines 145 to +153
string? line;
while ((line = await reader.ReadLineAsync()) is not null)
{
if (!suppressLogging)
{
_logger.LogTrace(
"{FileName}({ProcessId}) {Identifier}: {Line}",
FileName,
_process.Id,
identifier,
line
);
}
_logger.LogTrace(
"({ProcessId}) {Identifier}: {Line}",
_process.Id,
identifier,
line
);
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per-line process output trace logs no longer include the process FileName, which makes it harder to correlate output when multiple processes are running (previously it logged "{FileName}({ProcessId})..."). Consider including FileName (and optionally WorkingDirectory) in the trace template for better diagnostics.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

🎬 CLI E2E Test Recordings — 56 recordings uploaded (commit 954444d)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AllPublishMethodsBuildDockerImages ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording

📹 Recordings uploaded automatically from CI run #24123652916

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants