Prefer WebApplicationBuilder properties over ConfigureLogging, ConfigureServices, etc (#24323)

pull/24321/head
Kirk Larkin 2021-12-15 18:15:30 +00:00 committed by GitHub
parent 60e33714d5
commit 79361b6fa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 52 deletions

View File

@ -84,9 +84,7 @@ app.Run();
#elif FF
#region snippet_FF
var builder = WebApplication.CreateBuilder();
builder.Host.ConfigureLogging(logging =>
{
logging.AddFilter((provider, category, logLevel) =>
builder.Logging.AddFilter((provider, category, logLevel) =>
{
if (provider.Contains("ConsoleLoggerProvider")
&& category.Contains("Controller")
@ -105,7 +103,6 @@ builder.Host.ConfigureLogging(logging =>
return false;
}
});
});
#endregion
builder.Services.AddRazorPages();
@ -133,18 +130,17 @@ app.Run();
using Microsoft.Extensions.Logging.AzureAppServices;
var builder = WebApplication.CreateBuilder();
builder.Host.ConfigureLogging(logging => logging.AddAzureWebAppDiagnostics())
.ConfigureServices(serviceCollection => serviceCollection
.Configure<AzureFileLoggerOptions>(options =>
builder.Logging.AddAzureWebAppDiagnostics();
builder.Services.Configure<AzureFileLoggerOptions>(options =>
{
options.FileName = "azure-diagnostics-";
options.FileSizeLimit = 50 * 1024;
options.RetainedFileCountLimit = 5;
})
.Configure<AzureBlobLoggerOptions>(options =>
});
builder.Services.Configure<AzureBlobLoggerOptions>(options =>
{
options.BlobName = "log.txt";
}));
});
#endregion
builder.Services.AddRazorPages();
@ -170,7 +166,7 @@ app.Run();
#elif MIN
#region snippet_MIN
var builder = WebApplication.CreateBuilder();
builder.Host.ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Warning));
builder.Logging.SetMinimumLevel(LogLevel.Warning);
#endregion
builder.Services.AddRazorPages();
@ -199,10 +195,9 @@ using Microsoft.Extensions.Logging.Console;
using Microsoft.Extensions.Logging.Debug;
var builder = WebApplication.CreateBuilder();
builder.Host.ConfigureLogging(logging =>
logging.AddFilter("System", LogLevel.Debug)
.AddFilter<DebugLoggerProvider>("Microsoft", LogLevel.Information)
.AddFilter<ConsoleLoggerProvider>("Microsoft", LogLevel.Trace));
builder.Logging.AddFilter("System", LogLevel.Debug);
builder.Logging.AddFilter<DebugLoggerProvider>("Microsoft", LogLevel.Information);
builder.Logging.AddFilter<ConsoleLoggerProvider>("Microsoft", LogLevel.Trace);
#endregion
builder.Services.AddRazorPages();
@ -227,17 +222,12 @@ app.MapRazorPages();
app.Run();
#elif WEL
#region snippet_WEL
using Microsoft.Extensions.Logging.Console;
using Microsoft.Extensions.Logging.Debug;
var builder = WebApplication.CreateBuilder();
builder.Host.ConfigureLogging(logging =>
{
logging.AddEventLog(eventLogSettings =>
builder.Logging.AddEventLog(eventLogSettings =>
{
eventLogSettings.SourceName = "MyLogs";
});
});
#endregion
builder.Services.AddRazorPages();