Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LoggerProviderDebugView.CalculateEnabledLogLevel when the level is None #103209

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/libraries/Microsoft.Extensions.Logging/src/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,31 @@ public List<LoggerProviderDebugView> Providers
{
LoggerInformation loggerInfo = logger.Loggers[i];
string providerName = ProviderAliasUtilities.GetAlias(loggerInfo.ProviderType) ?? loggerInfo.ProviderType.Name;
MessageLogger? messageLogger = logger.MessageLoggers?.FirstOrDefault(messageLogger => messageLogger.Logger == loggerInfo.Logger);
MessageLogger? messageLogger = FirstOrNull(logger.MessageLoggers, loggerInfo.Logger);

providers.Add(new LoggerProviderDebugView(providerName, messageLogger));
}

return providers;

// Find message logger or return null if there is no match. FirstOrDefault isn't used because MessageLogger is a struct.
static MessageLogger? FirstOrNull(MessageLogger[]? messageLoggers, ILogger logger)
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
{
if (messageLoggers is null || messageLoggers.Length == 0)
{
return null;
}

foreach (MessageLogger item in messageLoggers)
{
if (item.Logger == logger)
{
return item;
}
}

return null;
}
}
}

Expand Down
Loading