dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15k stars 4.67k forks source link

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

Open WernerMairl opened 2 years ago

WernerMairl commented 2 years ago

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 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

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

dotnet-issue-labeler[bot] commented 2 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

WernerMairl commented 2 years ago

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

sorry may be i have created a duplicate for this: https://github.com/dotnet/runtime/issues/35989 but we should find a solution or at least a better documentation....

jeffhandley commented 2 years ago

Tagging @maryamariyan since the bot didn't.

maryamariyan commented 2 years ago

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.

pavel-agarkov commented 1 year ago

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: LoggingConsoleLogLevel__Microsoft.Hosting.Lifetime but dots are replaced with underscores so logging level is not applied.

Are there any workarounds for this issue?

tarekgh commented 1 year ago

@pavel-agarkov can you try the workaround mentioned in the comment https://github.com/dotnet/runtime/issues/87130#issuecomment-1583859511

pavel-agarkov commented 1 year ago

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