Skip to content

LogLevel Filter by Category may be not working on Linux (AppServices) when dots in CategoryName are replaced by underscore #60534

Closed as duplicate

Description

@WernerMairl

Description

May be I'm doing something wrong, so any help is welcome....

I have up and running a asp net core app (5.0.11) with Microsoft.Extensions.Logging in place
(a really small default configuration).

The issue occurs only on my Azure AppService Alpine (Linux!) instance!

I like to change logfilter by category for debugging and tracing....
I have category hierarchies like "A.B.C.D"
I like to filter for parts of the hierarchs like "A.B" or "A.B.C"

  • I'm able to change loglevel behavior via appsettings,json without problems for "A.B" on Linux and Windows
  • I'm able to change loglevel behavior via Environment variables in Visual Studio (Windows) without problems for "A.B"
  • I'm able to change loglevel behavior via Environment variable on Linux for Category "A" (without dot)

I'm NOT able to change loglevel behavior via Environmnet Variable on Linux for Category "A.B" (DOT part of the hierarchy!

I know that Linux has different behavior in Environment variables
=> ":" translated into double-underscore => works!
=> "." translated into single-underscore => seems to have NO impact to the LogFilter engine...

I'm using IConfigurationRoot.DebugView to print out my logging configuration.
and it looks in the following way:

image

(same behavior for Console and ApplicationInsights)

for me it looks like the "_" must be re-translated somewhere into "." before it goes into the LoggerRuleSelector

May be this is a known bug (i remember a few not solvable issues in core 2.0 and 3)

regards
Werner

Reproduction Steps

  • asp net core app with logging in place (console logging should be enough)
    • EnvironmentLoggerProvider should be included (using default logger builder)
  • set logging default to "Warning" or "Information" via appsettings (not other settings needed)
  • try to set LogFilter to Trace for a categoryName that CONTAINS "." ON LINUX (Alpine asp net core 5 runtime container) VIA ENVIRONMENT Variable

Expected behavior

LogFilter should be working

Actual behavior

LogFilter Ignored

Regression?

No response

Known Workarounds

No response

Configuration

asp-net-core 5 runtime alpine container hosted as Azure App Service

Other information

No response

Activity

  1. ghost added
    untriaged
    on Oct 18, 2021
  2. WernerMairl commented on Oct 18, 2021

    @WernerMairl
    ContributorAuthor

    label: area-Extensions-Logging
    label: area-Extension-Configurations

    sorry may be i have created a duplicate for this:
    #35989
    but we should find a solution or at least a better documentation....

  3. jeffhandley commented on Oct 18, 2021

    @jeffhandley
    Member

    Tagging @maryamariyan since the bot didn't.

  4. added this to the Future milestone on Nov 3, 2021
  5. removed
    untriaged
    on Nov 3, 2021
  6. maryamariyan commented on Nov 3, 2021

    @maryamariyan
    Contributor

    for me it looks like the "_" must be re-translated somewhere into "." before it goes into the LoggerRuleSelector

    Is it _ or double underscore __?

    Would be good if you could please share a repro sample to help try the different cases you shared here.

  7. pavel-agarkov commented on Sep 4, 2023

    @pavel-agarkov

    Hi, we cannot provide log levels via Azure AppService -> Configuration -> Application settings
    since as stated in the documentation

    App setting names can't contain periods (.). If an app setting contains a period, the period is replaced with an underscore in the container.

    https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal

    For example according to the documentation
    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-7.0
    we need to provide the following environment variable: Logging__Console__LogLevel__Microsoft.Hosting.Lifetime
    but dots are replaced with underscores so logging level is not applied.

    Are there any workarounds for this issue?

  8. tarekgh commented on Sep 13, 2023

    @tarekgh
    Member

    @pavel-agarkov can you try the workaround mentioned in the comment #87130 (comment)

  9. pavel-agarkov commented on Sep 13, 2023

    @pavel-agarkov

    @tarekgh yes, we did something similar to that already. thank you.

  10. gioce90 commented on Jul 10, 2025

    @gioce90

    We’re experiencing the same issue.
    Recently, we added FusionCache to our web app hosted on an Azure App Service (Linux).

    When we configure logging directly in appsettings.json, everything works as expected:

      "Logging": {
        "LogLevel": {
          "Default": "Trace",
          "Microsoft": "Warning",
          "System": "Warning"
        },
        "ApplicationInsights": {
          "LogLevel": {
            "Default": "Trace",
            "Microsoft": "Warning",
            "System": "Warning",
           
            "ZiggyCreatures.Caching.Fusion.FusionCache": "Warning"
          }
        }
      },

    That's okay.
    However, before adding the "ZiggyCreatures.Caching.Fusion.FusionCache": "Warning" line, we tried to reduce the log verbosity via the Azure Portal, using Configuration > Application settings (environment variables).

    We attempted several combinations (using ., _ and __), but none of them worked.

    Logging__ApplicationInsights__LogLevel__ZiggyCreatures.Caching.Fusion
    Logging__ApplicationInsights__LogLevel__ZiggyCreatures_Caching_Fusion
    Logging__ApplicationInsights__LogLevel__ZiggyCreatures__Caching__Fusion
    Logging__ApplicationInsights__LogLevel__ZiggyCreatures.Caching.Fusion.FusionCache
    Logging__ApplicationInsights__LogLevel__ZiggyCreatures_Caching_Fusion_FusionCache
    Logging__ApplicationInsights__LogLevel__ZiggyCreatures__Caching__Fusion__FusionCache

    Then I suspected that the issue might be related to the dot (.) in the category name. So we tried:

    Logging__ApplicationInsights__LogLevel__ZiggyCreatures

    This one actually worked, and reduced the log level for FusionCache.

    As a final fix, we're configuring the full logger category inside appsettings.json.
    However, the behavior we observed when using environment variables in the Azure Portal is quite subtle and could easily lead to confusion or misconfiguration.

  11. mrek-msft commented on Feb 11, 2026

    @mrek-msft
    Member

    Issue is not specific to logging, but Configuration. It is more or less same as #35989 and #87130. Despite it is hard to solve without breaking change or questionable API change, people found suitable workarounds for this issue.

    First suitable workaround was briefly documented in Note section of Logging docs and linked StackOverflow thread. Workaround requires control over environment but do not require change to application code.

    Different suitable workaround is described in comment #87130 (comment). This workaround in opposition do not requires significant changes in env setting, except using env vars with specific dot replacement. However it does requires code change.

  12. mrek-msft commented on Feb 12, 2026

    @mrek-msft
    Member

    Triage: Discussed in team triage and we think there is no additional action needed.

  13. modified the milestones: Future, 11.0.0 on Feb 12, 2026
  14. gioce90 commented on Feb 13, 2026

    @gioce90

    I think talking about "breaking changes" is a terrible excuse. This fix could easily be introduced with an optional parameter in the configuration, so nothing breaks.

  15. rosebyte commented on Feb 13, 2026

    @rosebyte
    Member

    How should the optional parameter look? Please feel free to propose an API that would solve this issue. The biggest problem I see is that we lose information by replacing the dots. That loss then prevents us from distinguishing between what was originally a dot and what was an actual underscore.

  16. tarekgh commented on Feb 13, 2026

    @tarekgh
    Member

    Here is the API can be used to address this issue nicely:

    Proposal

       namespace Microsoft.Extensions.Configuration.EnvironmentVariables
       {
           public partial class EnvironmentVariablesConfigurationSource : IConfigurationSource
           {
               // NEW: A string that, when found in env var keys, is replaced with "."
               // Default is null (no replacement, backward compatible)
               public string? DotReplacement { get; set; }
           }
       }
    
       // EnvironmentVariablesConfigurationProvider — new constructor overload
       namespace Microsoft.Extensions.Configuration.EnvironmentVariables
       {
           public partial class EnvironmentVariablesConfigurationProvider : ConfigurationProvider
           {
               // NEW
               public EnvironmentVariablesConfigurationProvider(string? prefix, string? dotReplacement) { }
           }
       }

    Usage:

       builder.Configuration.AddEnvironmentVariables(source =>
       {
           source.DotReplacement = "_._";
       });

    Alternative design

    This is more flexible but less discoverable.

       namespace Microsoft.Extensions.Configuration.EnvironmentVariables
       {
           public partial class EnvironmentVariablesConfigurationSource : IConfigurationSource
           {
               // NEW: Custom key normalizer; if null, uses default __ → : behavior
               public Func<string, string>? KeyNormalizer { get; set; }
           }
       }

    I added the same proposal to #35989 description too. Will be good to follow up there.

  17. gioce90 commented on Feb 13, 2026

    @gioce90

    How should the optional parameter look? Please feel free to propose an API that would solve this issue. The biggest problem I see is that we lose information by replacing the dots. That loss then prevents us from distinguishing between what was originally a dot and what was an actual underscore.

    Avoiding "home-made" solutions, should be possible to resolve this calling a MS's solution... for example with a key in the AppService's Env variables called (for example) "ResolveDotsForConfiguration":true

    Is just an idea.

  18. locked and limited conversation to collaborators on Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions