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 1 month ago by SolarOrbiter265

How can I override an Azure Function logging filter for a dotted category using App Service settings?

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

I have an Azure Function app that currently configures an "Information" logging filter for the MyCompany.IAM.AssetGovernance category using

appsettings.json

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

This category is derived from the C# namespace used for writing logs. I need to change this specific category's logging filter to "Debug" at runtime without modifying appsettings.json or redeploying the app.

I attempted to set an App Service app setting as follows:

TEXT
Logging__LogLevel__MyCompany.IAM.AssetGovernance

However, App Service replaces periods (".") with underscores ("_") in configuration keys, causing a mismatch because it transforms the key to something like Logging:LogLevel:MyCompany_IAM_AssetGovernance. Using Logging__LogLevel__MyCompany works, but that is too broad, affecting all logs under that namespace.

Is there a way to specifically configure the logging filter to "Debug" for the MyCompany.IAM.AssetGovernance category via App Service app settings?

For details on how App Service transforms configuration keys, see the documentation:

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 1 month ago

0

The short answer is that there isn’t currently a supported way to override only the "MyCompany.IAM.AssetGovernance" filter via App Service app settings. Because any periods (".") in your configuration key are replaced with underscores ("_") when using App Service settings (for both Linux and custom containers), a key like

Logging__LogLevel__MyCompany.IAM.AssetGovernance

ends up being normalized to something like Logging:LogLevel:MyCompany_IAM_AssetGovernance and no longer matches the full category name ("MyCompany.IAM.AssetGovernance") that the logging system uses for lookup.

The only workaround today is to use a broader key (for example, overriding at the "MyCompany" level), but that will affect all logs under that namespace (and likely produce more log entries than desired). Alternatively, you might consider:

  • Modifying your code to use a custom logging configuration provider that can map the transformed key back to the original category name.
  • Adjusting the namespace of the component(s) so that you don’t have the really long dotted scope.

But in terms of simply setting App Service app settings and having them apply via the standard configuration binding mechanism, there isn’t a built‑in way to override the setting only for the fully-qualified category containing periods.

For more details on how App Service transforms configuration keys, see the documentation:

Configure common settings for App Service

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 MeteorNomad937 1 month 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.

Answer by QuasarRanger772 1 month 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 PlanetaryNomad245 1 month 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.

Discussion

No comments yet.