Is there a way to get all logging providers, and for each their LogLevel settings?

41 Views Asked by At

For the ASP.NET ILogger system, is there a way to get all providers that are running in my app? And then for each provider get the LogLevels set for that provider?

I want to log the logging as it's configured.

I'm running Blazor server side on .NET 8 if that makes a difference.

I initialize my loggers as follows:

if (builder.Environment.IsDevelopment())
{
    Debug.WriteLine("Adding dev logging providers");
    builder.Logging.ClearProviders();
    builder.Logging.AddJsonConsole();
    builder.Logging.AddDebug();
    builder.Logging.AddFileLogger();
    builder.Logging.AddAzureBlobLogger();
}
else
{
    Debug.WriteLine("Adding production logging providers");
    builder.Logging.AddAzureBlobLogger();
    builder.Logging.AddAzureWebAppDiagnostics();
    builder.Services.Configure<AzureFileLoggerOptions>(options =>
    {
        options.FileName = "azure-diagnostics-";
        options.FileSizeLimit = 50 * 1024;
        options.RetainedFileCountLimit = 5;
    });
}

// connect to ApplicationInsights
if (config.GetValue<bool>("ApplicationInsights:Enabled"))
{
    Debug.WriteLine("Connect to Application Insights");
    builder.Logging.AddApplicationInsights();
    builder.Services.AddApplicationInsightsTelemetry();
}

Note: AddFileLogger() and AddAzureBlobLogger() are loggers I created (after spending 2 days trying and failing to get SeriLog to work logging to Azure BLOB storage).

What is driving me on this is I want to make sure my AzureBlobLogger has connected to Azure BLOB storage successfully. Secondarily, I'd like to log the log levels to verify I have those set correctly (I had a case where there was an override I was not aware of).

0

There are 0 best solutions below