Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 2 months ago by ZenithScout334

How can I override the logging filter for a dotted namespace via App Service settings in an Azure Function app?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I have an Azure Function app that is configured with an explicit logging filter for the MyCompany.IAM.AssetGovernance category in appsettings.json:

JSON
{ "Logging": { "LogLevel": { "MyCompany.IAM.AssetGovernance": "Information" } } }

This category is based on the C# namespace that writes the logs. I want to change the logging filter to "Debug" for the MyCompany.IAM.AssetGovernance category at runtime without modifying appsettings.json and redeploying the Function app.

To achieve this, I attempted to use an App Service app setting like this:

NONE
Logging__LogLevel__MyCompany.IAM.AssetGovernance

However, App Service replaces periods (".") with underscores ("_") so the key becomes MyCompany_IAM_AssetGovernance, which does not match the category in appsettings.json. Setting it to Logging__LogLevel__MyCompany works, but that change applies too broadly to all logs under that scope.

Is there any way to specifically override the logging filter for MyCompany.IAM.AssetGovernance via App Service app settings?

Docs:

In a default Linux app service or a custom Linux container, any nested
JSON key structure in the app setting name like
ApplicationInsights:InstrumentationKey needs to be configured in App
Service as ApplicationInsights__InstrumentationKey for the key name.
In other words, any : should be replaced by __ (double underscore).
Any periods in the app setting name will be replaced with a _ (single underscore).

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

0

Comments 0

Answers 4

Views 55

4 Answers

Answer by StackOverflowTychoAI Agent 2 months ago

0

When configuring logging filters via App Service app settings, the conversion behavior (replacing periods “.” with underscores “_”) means you cannot target a fully qualified category name (like MyCompany.IAM.AssetGovernance) directly. This is a known constraint:

  • App Service transforms nested JSON key names so that any periods in the key (e.g. MyCompany.IAM.AssetGovernance) become underscores.

  • As a result, setting an app setting such as

    Logging__LogLevel__MyCompany.IAM.AssetGovernance
    

    ends up looking for a key named “MyCompany_IAM_AssetGovernance” which does not match the category as defined in your appsettings.json.

Currently, there isn’t a built‑in way to “escape” or otherwise preserve the periods in the environment variable key so that you can override the filter just for the specific category via App Service settings. The only supported behavior is to override at a higher level (e.g. Logging__LogLevel__MyCompany) which will affect more than just that one namespace.

Possible workarounds include:

  • Changing the category in code or configuration: If you have control over the logging configuration in your application startup, you could programmatically read an additional environment variable (with a name that doesn’t have periods) and apply a more granular filter.
  • Using host.json (for Functions): In some scenarios you might adjust logging settings through host.json if that supports a more granular configuration, but this is limited by the Functions runtime.

For now, using App Service app settings alone, you cannot override the logging filter for a namespace that contains periods without affecting a broader scope.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Answer by CometPathfinder827 3 months ago

0

I think there's a lot of commonality between App Settings and Environment Variables. According to this GitHub Issue, wrapping the whole setting in quotes works for environment variables so might be worth a try.

No comments yet.

Answer by NovaEnvoy470 3 months ago

0

This document has the following note:

When configuring environment variables with names that contain . (periods) in macOS and Linux, consider the "Exporting a variable with a dot (.) in it" question on Stack Exchange and its corresponding accepted answer.

The referenced answer basically says that you can't really define a variable with a period in its name without doing some contortions.

Furthermore, I don't know that changing the configuration at run-time would allow the change to take place immediately. As far as I can tell, the configuration is applied when the application is created, and is not checked dynamically after that point.

If you need to filter out log messages based on some kind of dynamic state, I'd recommend using a Filter function instead. You would set the configured log level to the most verbose setting you might want to use, and then the filter could check the value of some stateful object that you can change on-demand.

If you can handle an app refresh, but simply don't want to re-deploy the appsettings.json file to your app, it should be possible to set the logging framework to use a different configuration source when it's starting up. For example, I think you could read a JSON object from a blob, use a ConfigurationBuilder to AddJsonStream from that blob content, create a configuration object from the builder, and then configure your logging framework to use that configuration source:

CSHARP
builder.Services.AddLogging(loggingBuilder => { loggingBuilder.AddConfiguration(configuration.GetSection("Logging")); });

No comments yet.

Answer by CometMariner853 3 months ago

0

I'm pretty sure I do this on Azure by adding an environment variable with a key looking like this:

YAML
Logging:LogLevel:MyCompany.IAM.AssetGovernance

So, using colons for nested objects in the appsettings.json file.

No comments yet.

Discussion

No comments yet.