diff --git a/src/OpenFeature.DependencyInjection/Internal/FeatureLifecycleManager.cs b/src/OpenFeature.DependencyInjection/Internal/FeatureLifecycleManager.cs
index 4b6ad426..9472b4f9 100644
--- a/src/OpenFeature.DependencyInjection/Internal/FeatureLifecycleManager.cs
+++ b/src/OpenFeature.DependencyInjection/Internal/FeatureLifecycleManager.cs
@@ -3,7 +3,7 @@
namespace OpenFeature.Internal;
-internal sealed class FeatureLifecycleManager : IFeatureLifecycleManager
+internal sealed partial class FeatureLifecycleManager : IFeatureLifecycleManager
{
private readonly Api _featureApi;
private readonly IServiceProvider _serviceProvider;
@@ -19,7 +19,7 @@ public FeatureLifecycleManager(Api featureApi, IServiceProvider serviceProvider,
///
public async ValueTask EnsureInitializedAsync(CancellationToken cancellationToken = default)
{
- _logger.LogInformation("Starting initialization of the feature provider");
+ this.LogStartingInitializationOfFeatureProvider();
var featureProvider = _serviceProvider.GetService();
if (featureProvider == null)
{
@@ -31,7 +31,13 @@ public async ValueTask EnsureInitializedAsync(CancellationToken cancellationToke
///
public async ValueTask ShutdownAsync(CancellationToken cancellationToken = default)
{
- _logger.LogInformation("Shutting down the feature provider.");
+ this.LogShuttingDownFeatureProvider();
await _featureApi.ShutdownAsync().ConfigureAwait(false);
}
+
+ [LoggerMessage(200, LogLevel.Information, "Starting initialization of the feature provider")]
+ partial void LogStartingInitializationOfFeatureProvider();
+
+ [LoggerMessage(200, LogLevel.Information, "Shutting down the feature provider")]
+ partial void LogShuttingDownFeatureProvider();
}
diff --git a/src/OpenFeature.Hosting/HostedFeatureLifecycleService.cs b/src/OpenFeature.Hosting/HostedFeatureLifecycleService.cs
index 1e3b3c30..dd9bcbee 100644
--- a/src/OpenFeature.Hosting/HostedFeatureLifecycleService.cs
+++ b/src/OpenFeature.Hosting/HostedFeatureLifecycleService.cs
@@ -5,11 +5,11 @@
namespace OpenFeature;
///
-/// A hosted service that manages the lifecycle of features within the application.
-/// It ensures that features are properly initialized when the service starts
+/// A hosted service that manages the lifecycle of features within the application.
+/// It ensures that features are properly initialized when the service starts
/// and gracefully shuts down when the service stops.
///
-public sealed class HostedFeatureLifecycleService : IHostedLifecycleService
+public sealed partial class HostedFeatureLifecycleService : IHostedLifecycleService
{
private readonly ILogger _logger;
private readonly IFeatureLifecycleManager _featureLifecycleManager;
@@ -74,7 +74,7 @@ private async Task InitializeIfStateMatchesAsync(FeatureStartState expectedState
{
if (_featureLifecycleStateOptions.Value.StartState == expectedState)
{
- _logger.LogInformation("Initializing the Feature Lifecycle Manager for state {State}.", expectedState);
+ this.LogInitializingFeatureLifecycleManager(expectedState);
await _featureLifecycleManager.EnsureInitializedAsync(cancellationToken).ConfigureAwait(false);
}
}
@@ -86,8 +86,14 @@ private async Task ShutdownIfStateMatchesAsync(FeatureStopState expectedState, C
{
if (_featureLifecycleStateOptions.Value.StopState == expectedState)
{
- _logger.LogInformation("Shutting down the Feature Lifecycle Manager for state {State}.", expectedState);
+ this.LogShuttingDownFeatureLifecycleManager(expectedState);
await _featureLifecycleManager.ShutdownAsync(cancellationToken).ConfigureAwait(false);
}
}
+
+ [LoggerMessage(200, LogLevel.Information, "Initializing the Feature Lifecycle Manager for state {State}.")]
+ partial void LogInitializingFeatureLifecycleManager(FeatureStartState state);
+
+ [LoggerMessage(200, LogLevel.Information, "Shutting down the Feature Lifecycle Manager for state {State}")]
+ partial void LogShuttingDownFeatureLifecycleManager(FeatureStopState state);
}