ILoggingBuilder - clear some providers?

David Thielen 2,796 Reputation points
2023-07-25T22:54:42.9166667+00:00

When my code starts, as suggested, I have the following:

		if (builder.Environment.IsDevelopment())
		{
			builder.Logging.ClearProviders();
			builder.Logging.AddJsonConsole();
			builder.Logging.AddDebug();
		}

Now for production on an Azure app service, please correct me if I'm wrong, as I change nothing it'll set up the following providers (assuming I don't make any calls) - is this correct?

  • Console
  • Debug
  • EventSource
  • EventLog (Windows only) And that feeds them across with all the {name} key:values and scopes passed to be displayed as desired - correct?

And that feeds them across with all the {name} key:values and scopes passed to be displayed as desired - correct?

Question: Where does the Console & Debug providers go in production?

Question: When I turn on log to the stream in Azure and set it to verbose/debug, it ignores the configuration I set in the appsettings.json and is giving me debug level log output for namespaces I set to warning. Shouldn't appsettings.json stop those log statements from ever getting to Azure?

Question: Is the following the correct way to add in Application Insights?

		if (useApplicationInsights)
		{
			builder.Logging.AddApplicationInsights();
			builder.Services.AddApplicationInsightsTelemetry();
		}

thanks - dave

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,037 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,400 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,407 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tiny Wang-MSFT 2,321 Reputation points Microsoft Vendor
    2023-07-26T02:54:36.7833333+00:00

    Hi @David Thielen , I could answer part of your questions.

    Question: Where does the Console & Debug providers go in production?

    I think this section explained the location. You could find the logs in Kudu site(https://<app-name>.scm.azurewebsites.net)

    User's image

    Question: Is the following the correct way to add in Application Insights?

    I think this official document could help you.

    var builder = WebApplication.CreateBuilder(args); // The following line enables Application Insights telemetry collection. 
    
    builder.Services.AddApplicationInsightsTelemetry();