Use IIdentityLogger for MSAL logging in TokenAcquisition and ManagedIdentityClientAssertion (#3820)#3880
Conversation
…dentityClientAssertion Route MSAL's internal logging through IdentityLoggerAdapter (the IIdentityLogger overload of WithLogging) instead of the legacy LogCallback. Previously the whole MSAL log line (version, platform, correlation id, message) was flattened into a single unstructured ILogger message and the log-level threshold was computed manually. IdentityLoggerAdapter preserves per-entry log levels and lets ILogger own filtering, matching the pattern already used for Wilson logging in MicrosoftIdentityBaseAuthenticationBuilder. Removes the now-unused Log callback and ConvertMicrosoftExtensionsLogLevelToMsal helpers in both types, and adds the Microsoft.IdentityModel.LoggingExtensions package reference to the Certificateless project. Fixes AzureAD#3820 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
trwalke
left a comment
There was a problem hiding this comment.
The log level we use in MSAL is slightly different from the one used in IdWeb since IdWeb used the standard .Net log levels. will this translation still happen correctly?
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-10.0#log-level
|
Good question — there are two hops now (MSAL
4/5 are identical. Only |
Summary
Fixes #3820.
TokenAcquisitionandManagedIdentityClientAssertionconfigured MSAL's internal logging via the legacyWithLogging(LogCallback, …)overload. That callback hands back a single pre-formatted string, so the entire MSAL log line (MSAL version, runtime, OS, correlation id, message) was flattened into one unstructuredILoggermessage, and the log-level threshold was computed up front by a hand-rolledConvertMicrosoftExtensionsLogLevelToMsalhelper.This PR switches all MSAL logging configuration to the
IIdentityLoggeroverload, passingIdentityLoggerAdapterfromMicrosoft.IdentityModel.LoggingExtensions— the same adapter IdentityWeb already uses for Wilson logging inMicrosoftIdentityBaseAuthenticationBuilder. MSAL now emits each log entry at its proper level andILoggerowns the filtering.Changes
TokenAcquisition.cs(confidential client build) — usenew IdentityLoggerAdapter(_logger).TokenAcquisition.ManagedIdentity.cs(managed identity build) — usenew IdentityLoggerAdapter(_logger).ManagedIdentityClientAssertion.cs(Certificateless) — usenew IdentityLoggerAdapter(_logger); added theMicrosoft.IdentityModel.LoggingExtensionspackage reference to the project.Logcallbacks andConvertMicrosoftExtensionsLogLevelToMsalhelpers from both types.Notes / out of scope
ManagedIdentityClientAssertion's log entries carry the source contextMicrosoft.Identity.Web.DefaultCertificateLoader. That comes from theILoggercategory supplied by the caller that constructs the assertion, not from the logging API used here, so it is intentionally left out of this change. Happy to follow up separately if a dedicated category is desired.Testing
Microsoft.Identity.Web.TokenAcquisitionandMicrosoft.Identity.Web.Certificatelessbuild clean (0 warnings) across all target frameworks.Microsoft.Identity.Web.Testbuilds clean; no existing tests referenced the removed private helpers.