diff --git a/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs b/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs
index 3b47ee839bc..46513404b28 100644
--- a/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs
+++ b/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
+using Microsoft.Extensions.Logging;
namespace Aspire.Hosting.ApplicationModel;
@@ -242,4 +243,9 @@ public sealed class ExecuteCommandContext
/// The cancellation token.
///
public required CancellationToken CancellationToken { get; init; }
+
+ ///
+ /// The logger for the resource.
+ ///
+ public required ILogger Logger { get; init; }
}
diff --git a/src/Aspire.Hosting/ApplicationModel/ResourceCommandService.cs b/src/Aspire.Hosting/ApplicationModel/ResourceCommandService.cs
index d3b07a0db98..95a4043e980 100644
--- a/src/Aspire.Hosting/ApplicationModel/ResourceCommandService.cs
+++ b/src/Aspire.Hosting/ApplicationModel/ResourceCommandService.cs
@@ -161,7 +161,8 @@ internal async Task ExecuteCommandCoreAsync(string resourc
{
ResourceName = resourceId,
ServiceProvider = _serviceProvider,
- CancellationToken = cancellationToken
+ CancellationToken = cancellationToken,
+ Logger = logger
};
var result = await annotation.ExecuteCommand(context).ConfigureAwait(false);
diff --git a/tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go b/tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go
index dc09cf3410b..b34f992ab29 100644
--- a/tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go
+++ b/tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go
@@ -8187,6 +8187,31 @@ func (s *ExecuteCommandContext) SetCancellationToken(value *CancellationToken) (
return result.(*ExecuteCommandContext), nil
}
+// Logger gets the Logger property
+func (s *ExecuteCommandContext) Logger() (*ILogger, error) {
+ reqArgs := map[string]any{
+ "context": SerializeValue(s.Handle()),
+ }
+ result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/ExecuteCommandContext.logger", reqArgs)
+ if err != nil {
+ return nil, err
+ }
+ return result.(*ILogger), nil
+}
+
+// SetLogger sets the Logger property
+func (s *ExecuteCommandContext) SetLogger(value *ILogger) (*ExecuteCommandContext, error) {
+ reqArgs := map[string]any{
+ "context": SerializeValue(s.Handle()),
+ }
+ reqArgs["value"] = SerializeValue(value)
+ result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/ExecuteCommandContext.setLogger", reqArgs)
+ if err != nil {
+ return nil, err
+ }
+ return result.(*ExecuteCommandContext), nil
+}
+
// ExternalServiceResource wraps a handle for Aspire.Hosting/Aspire.Hosting.ExternalServiceResource.
type ExternalServiceResource struct {
ResourceBuilderBase
diff --git a/tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java b/tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java
index e1bb1aa0e9c..233f377bb0f 100644
--- a/tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java
+++ b/tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java
@@ -9131,6 +9131,25 @@ public ExecuteCommandContext setCancellationToken(CancellationToken value) {
return (ExecuteCommandContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/ExecuteCommandContext.setCancellationToken", reqArgs);
}
+ /** Gets the Logger property */
+ public ILogger logger() {
+ Map reqArgs = new HashMap<>();
+ reqArgs.put("context", AspireClient.serializeValue(getHandle()));
+ return (ILogger) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/ExecuteCommandContext.logger", reqArgs);
+ }
+
+ /** Sets the Logger property */
+ public ExecuteCommandContext setLogger(ILogger value) {
+ Map reqArgs = new HashMap<>();
+ reqArgs.put("context", AspireClient.serializeValue(getHandle()));
+ reqArgs.put("value", AspireClient.serializeValue(value));
+ return (ExecuteCommandContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/ExecuteCommandContext.setLogger", reqArgs);
+ }
+
+ public ExecuteCommandContext setLogger(HandleWrapperBase value) {
+ return setLogger(new ILogger(value.getHandle(), value.getClient()));
+ }
+
}
// ===== ExecuteCommandResult.java =====
diff --git a/tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py b/tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py
index 8c2d50371dd..664a1132401 100644
--- a/tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py
+++ b/tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py
@@ -3343,6 +3343,23 @@ def cancel(self) -> None:
)
token.cancel()
+ @_uncached_property
+ def logger(self) -> AbstractLogger:
+ """Gets the Logger property"""
+ result = self._client.invoke_capability(
+ 'Aspire.Hosting.ApplicationModel/ExecuteCommandContext.logger',
+ {'context': self._handle}
+ )
+ return typing.cast(AbstractLogger, result)
+
+ @logger.setter
+ def logger(self, value: AbstractLogger) -> None:
+ """Sets the Logger property"""
+ self._client.invoke_capability(
+ 'Aspire.Hosting.ApplicationModel/ExecuteCommandContext.setLogger',
+ {'context': self._handle, 'value': value}
+ )
+
class InitializeResourceEvent:
"""Type class for InitializeResourceEvent."""
diff --git a/tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs b/tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs
index 164d20528a9..b5ea48a7857 100644
--- a/tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs
+++ b/tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs
@@ -7116,6 +7116,25 @@ impl ExecuteCommandContext {
let handle: Handle = serde_json::from_value(result)?;
Ok(ExecuteCommandContext::new(handle, self.client.clone()))
}
+
+ /// Gets the Logger property
+ pub fn logger(&self) -> Result> {
+ let mut args: HashMap = HashMap::new();
+ args.insert("context".to_string(), self.handle.to_json());
+ let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/ExecuteCommandContext.logger", args)?;
+ let handle: Handle = serde_json::from_value(result)?;
+ Ok(ILogger::new(handle, self.client.clone()))
+ }
+
+ /// Sets the Logger property
+ pub fn set_logger(&self, value: &ILogger) -> Result> {
+ let mut args: HashMap = HashMap::new();
+ args.insert("context".to_string(), self.handle.to_json());
+ args.insert("value".to_string(), value.handle().to_json());
+ let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/ExecuteCommandContext.setLogger", args)?;
+ let handle: Handle = serde_json::from_value(result)?;
+ Ok(ExecuteCommandContext::new(handle, self.client.clone()))
+ }
}
/// Wrapper for Aspire.Hosting/Aspire.Hosting.ExternalServiceResource
diff --git a/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts b/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts
index c155ffe8f83..a531d10b22e 100644
--- a/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts
+++ b/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts
@@ -1501,6 +1501,17 @@ export class ExecuteCommandContext {
}
};
+ /** Gets the Logger property */
+ logger = {
+ get: async (): Promise => {
+ const handle = await this._client.invokeCapability(
+ 'Aspire.Hosting.ApplicationModel/ExecuteCommandContext.logger',
+ { context: this._handle }
+ );
+ return new Logger(handle, this._client);
+ },
+ };
+
}
// ============================================================================