Skip to content

TokenAcquisition and exposes MSAL logging as unstructured logs #3820

@kevincathcart-cas

Description

@kevincathcart-cas

TokenAcquisition still using the old LogCallback .WithLogging API to expose the internal logging of MSAL, instead of the newer IIdentityLogger based overload that supports somewhat more structured logging.

ConfidentialClientApplicationBuilder builder = ConfidentialClientApplicationBuilder
.CreateWithApplicationOptions(mergedOptions.ConfidentialClientApplicationOptions)
.WithHttpClientFactory(_httpClientFactory)
.WithLogging(
Log,
ConvertMicrosoftExtensionsLogLevelToMsal(_logger),
enablePiiLogging: mergedOptions.ConfidentialClientApplicationOptions.EnablePiiLogging)
.WithExperimentalFeatures();

ManagedIdentityApplicationBuilder miBuilder = ManagedIdentityApplicationBuilder
.Create(managedIdentityId)
.WithLogging(
Log,
ConvertMicrosoftExtensionsLogLevelToMsal(_logger),
enablePiiLogging: enablePiiLogging);

The same is also true of Microsoft.Identity.Web.Certificateless's ManagedIdentityClientAssertion class (which amusingly ends up with a logger Source context of Microsoft.Identity.Web.DefaultCertificateLoader, despite the assembly name):

builder = builder.WithLogging(Log, ConvertMicrosoftExtensionsLogLevelToMsal(_logger), enablePiiLogging: false);

This results in log lines whose message portions look like the following:

False MSAL 4.83.1.0 MSAL.NetCore .NET 10.0.7 Microsoft Windows 10.0.26200 [2026-05-18 16:29:25Z - OMITTING_CORRELATION _GUID] === Token Acquisition (ConfidentialAuthCodeRequest) started: Scopes: Authority Host: login.microsoftonline.com

Elsewhere Microsoft.Identity.Web has been using IIdentityLogger via IdentityLoggerAdapter from Microsoft.IdentityModel.LoggingExtensions. If it is feasible to switch TokenAcquisition and ManagedIdentityClientAssertion over to using IdentityLoggerAdapter, I would appreciate it.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions