Skip to content

Empty appsettings.json FeatureManagement section returns internal GetFeatureNamesAsync #144

Closed
@simonauner

Description

@simonauner

Not sure if the title reflects the issue correctly, but I have a dotnet app that uses Microsoft.FeatureManagement 2.3.0.

It has this configured in its appsettings.json:

  "FeatureManagement": {
    "MyFeature": false
  },

And then I thought it would be helpful to have a logger that logs all enabled or disabled features upon startup:

    public class FeatureLogger : IFeatureLogger
    {
        private readonly IFeatureManager _featureManager;
        private readonly ILogger _logger;

        public FeatureLogger(IFeatureManager featureManager, ILogger logger)
        {
            _featureManager = featureManager;
            _logger = logger.ForContext<FeatureLogger>();
        }

        public async Task LogFeatureStatus()
        {
            var features = _featureManager.GetFeatureNamesAsync();
            await foreach (var feature in features)
            {
                var isEnabled = await _featureManager.IsEnabledAsync(feature);
                _logger.Information("Feature {Feature} is {Status}", feature, isEnabled ? "enabled" : "disabled");
            }
        }
    }

It works as expected as long as I have something in the FeatureManagement section in appsettings.json:

[10:41:32 INF] Feature MyFeature is disabled

But if I decide to remove this MyFeature prop from FeatureManagement in appsettings.json:

  "FeatureManagement": {
  },

then the following is logged:

[10:42:57 INF] Feature applicationName is disabled
[10:42:57 INF] Feature ASPNETCORE_ENVIRONMENT is disabled
[10:42:57 INF] Feature ASPNETCORE_URLS is disabled
[10:42:57 INF] Feature BAMF_DESKTOP_FILE_HINT is disabled
[10:42:57 INF] Feature contentRoot is disabled
[10:42:57 INF] Feature DBUS_SESSION_BUS_ADDRESS is disabled
[10:42:57 INF] Feature DESKTOP_SESSION is disabled
[10:42:57 INF] Feature DISPLAY is disabled
[10:42:57 INF] Feature DOTNET_ROOT is disabled
[10:42:57 INF] Feature ENVIRONMENT is disabled
[10:42:57 INF] Feature GDMSESSION is disabled
[10:42:57 INF] Feature GIO_LAUNCHED_DESKTOP_FILE is disabled
[10:42:57 INF] Feature GIO_LAUNCHED_DESKTOP_FILE_PID is disabled
[10:42:57 INF] Feature GJS_DEBUG_OUTPUT is disabled
[10:42:57 INF] Feature GJS_DEBUG_TOPICS is disabled
[10:42:57 INF] Feature GNOME_DESKTOP_SESSION_ID is disabled
[10:42:57 INF] Feature GNOME_SHELL_SESSION_MODE is disabled
[10:42:57 INF] Feature GPG_AGENT_INFO is disabled
[10:42:57 INF] Feature GTK_MODULES is disabled
[10:42:57 INF] Feature HOME is disabled
[10:42:57 INF] Feature IM_CONFIG_PHASE is disabled
[10:42:57 INF] Feature INVOCATION_ID is disabled
[10:42:57 INF] Feature JOURNAL_STREAM is disabled
[10:42:57 INF] Feature LANG is disabled
[10:42:57 INF] Feature LANGUAGE is disabled
[10:42:57 INF] Feature LC_ADDRESS is disabled
[10:42:57 INF] Feature LC_IDENTIFICATION is disabled
[10:42:57 INF] Feature LC_MEASUREMENT is disabled
[10:42:57 INF] Feature LC_MONETARY is disabled
[10:42:57 INF] Feature LC_NAME is disabled
[10:42:57 INF] Feature LC_NUMERIC is disabled
[10:42:57 INF] Feature LC_PAPER is disabled
[10:42:57 INF] Feature LC_TELEPHONE is disabled
[10:42:57 INF] Feature LC_TIME is disabled
[10:42:57 INF] Feature Logging is disabled
[10:42:57 INF] Feature LOGNAME is disabled
[10:42:57 INF] Feature MANAGERPID is disabled
[10:42:57 INF] Feature PAPERSIZE is disabled
[10:42:57 INF] Feature PATH is disabled
[10:42:57 INF] Feature PWD is disabled
[10:42:57 INF] Feature QT_ACCESSIBILITY is disabled
[10:42:57 INF] Feature QT_IM_MODULE is disabled
[10:42:57 INF] Feature ROOT is disabled
[10:42:57 INF] Feature Serilog is disabled
[10:42:57 INF] Feature SESSION_MANAGER is disabled
[10:42:57 INF] Feature SHELL is disabled
[10:42:57 INF] Feature SHLVL is disabled
[10:42:57 INF] Feature SNAP is disabled
[10:42:57 INF] Feature SNAP_ARCH is disabled
[10:42:57 INF] Feature SNAP_COMMON is disabled
[10:42:57 INF] Feature SNAP_CONTEXT is disabled
[10:42:57 INF] Feature SNAP_COOKIE is disabled
[10:42:57 INF] Feature SNAP_DATA is disabled
[10:42:57 INF] Feature SNAP_INSTANCE_KEY is disabled
[10:42:57 INF] Feature SNAP_INSTANCE_NAME is disabled
[10:42:57 INF] Feature SNAP_LIBRARY_PATH is disabled
[10:42:57 INF] Feature SNAP_NAME is disabled
[10:42:57 INF] Feature SNAP_REAL_HOME is disabled
[10:42:57 INF] Feature SNAP_REEXEC is disabled
[10:42:57 INF] Feature SNAP_REVISION is disabled
[10:42:57 INF] Feature SNAP_USER_COMMON is disabled
[10:42:57 INF] Feature SNAP_USER_DATA is disabled
[10:42:57 INF] Feature SNAP_VERSION is disabled
[10:42:57 INF] Feature SSH_AGENT_PID is disabled
[10:42:57 INF] Feature SSH_AUTH_SOCK is disabled
[10:42:57 INF] Feature TERM is disabled
[10:42:57 INF] Feature URLS is disabled
[10:42:57 INF] Feature USER is disabled
[10:42:57 INF] Feature USERNAME is disabled
[10:42:57 INF] Feature WINDOWPATH is disabled
[10:42:57 INF] Feature XAUTHORITY is disabled
[10:42:57 INF] Feature XDG_CONFIG_DIRS is disabled
[10:42:57 INF] Feature XDG_CURRENT_DESKTOP is disabled
[10:42:57 INF] Feature XDG_DATA_DIRS is disabled
[10:42:57 INF] Feature XDG_MENU_PREFIX is disabled
[10:42:57 INF] Feature XDG_RUNTIME_DIR is disabled
[10:42:57 INF] Feature XDG_SESSION_CLASS is disabled
[10:42:57 INF] Feature XDG_SESSION_DESKTOP is disabled
[10:42:57 INF] Feature XDG_SESSION_TYPE is disabled
[10:42:57 INF] Feature XMODIFIERS is disabled
[10:42:57 INF] Feature _ is disabled
[10:42:57 INF] Feature _NO_DEBUG_HEAP is disabled

I would expect that when the FeatureManagement section is empty in appsettings.json, then no features are returned from GetFeatureNamesAsync.

Or am I missing someting in the configuration?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions