Remove traces from Azure.Identity category

Angela Calborean 71 Reputation points
2022-07-20T09:35:33.763+00:00

I have a .net Core 3.1 web app that connects to different Storage Accounts using Azure MSI. The services are initialized using the Azure.Core.Extensions nuget package.

var options = new BlobClientOptions
{
Diagnostics =
{
IsLoggingEnabled = false,
IsTelemetryEnabled = false,
IsDistributedTracingEnabled = false,
IsLoggingContentEnabled = false
},
Retry =
{
MaxRetries = 3,
Mode = RetryMode.Exponential,
NetworkTimeout = TimeSpan.FromSeconds(120),
Delay = TimeSpan.FromSeconds(0.7)
}
};
builder.AddBlobServiceClient(StorageAccountConfigurator.GetStorageAccountUri(accountName))
.WithName(accountName)
.ConfigureOptions(options);

Everything works ok, but in Application Insights I get too many traces with this message:

ManagedIdentityCredential.GetToken succeeded. Scopes: [ https://storage.azure.com/.default ]
These are traces with Severity level:Information, Category:Azure.Identity.

Azure.Identity does not appear as a independent category in the documentation:https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-6.0

I have tried to create a ApplicationInsightsFilter (implements ITelemetryProcessor) to catch such traces and exclude them from logs, but somehow they overpass it (while debugging I was not able to catch such traces).

Is there an option to stop them from appearing in the logs?

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,855 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,734 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AnuragSingh-MSFT 20,431 Reputation points
    2022-07-24T07:08:38.323+00:00

    Hi @Angela Calborean ,

    Thank you for reaching out to Microsoft Q&A for this question.

    I understand that you want to exclude the logs with the following information from ApplicationInsights:
    level: Information, Category:Azure.Identity

    Please note that you will not be able to exclude the logs based on the message, but you can setup filters for ApplicationInsights to only log messages with specific LogLevel and higher and for specific LogCategory.

    Therefore, with the requirement posted in the question, you could include the following in the appsettings.json file to filter out the messages with LogLevel<=Information && LogCategory = Azure.Identity

    {  
      "Logging": {  
        "LogLevel": {                    
          "Default": "Information"           //----For all types of log providers  
        },  
        "ApplicationInsights": {          //----Filters for ApplicationInsights  
          "LogLevel": {  
            "Azure.Identity": "Warning"        //-- only Log Warning, Error and Critical messages from Azure.Identity.  
          }  
        }  
      }  
    }  
    

    For more details on how the Logging is configured, see Configure logging.
    The link here contains various LogLevels available and their description.

    Also note that the link below only contains some categories used by ASP.NET Core and Entity Framework Core. There may be other categories used in application, which can be confogured for logging as mentoined above.
    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-6.0

    Please let me know if you have any questions.

    ---
    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.