React to Logging API changes (#787)

This commit is contained in:
BrennanConroy 2017-05-03 12:58:54 -07:00 committed by GitHub
parent 6ab84e0f27
commit 6ff97fc83b
6 changed files with 20 additions and 24 deletions

View File

@ -110,10 +110,8 @@ namespace MusicStore
}); });
} }
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app)
{ {
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage"); app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage");
// Display custom error page in production when error occurs // Display custom error page in production when error occurs

View File

@ -159,10 +159,8 @@ namespace MusicStore
} }
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app)
{ {
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage"); app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage");
// Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline. // Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline.

View File

@ -3,6 +3,7 @@ using System.IO;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.HttpSys; using Microsoft.AspNetCore.Server.HttpSys;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace MusicStore namespace MusicStore
{ {
@ -21,11 +22,11 @@ namespace MusicStore
.UseIISIntegration() .UseIISIntegration()
.UseStartup("MusicStore"); .UseStartup("MusicStore");
if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal)) var environment = builder.GetSetting("environment") ??
{
var environment = builder.GetSetting("environment") ??
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal))
{
if (string.Equals(environment, "NtlmAuthentication", System.StringComparison.Ordinal)) if (string.Equals(environment, "NtlmAuthentication", System.StringComparison.Ordinal))
{ {
// Set up NTLM authentication for WebListener like below. // Set up NTLM authentication for WebListener like below.
@ -47,6 +48,15 @@ namespace MusicStore
builder.UseKestrel(); builder.UseKestrel();
} }
builder.ConfigureLogging(factory =>
{
factory.AddConsole();
var logLevel = string.Equals(environment, "Development", StringComparison.Ordinal) ? LogLevel.Information : LogLevel.Warning;
factory.AddFilter("Console", level => level >= logLevel);
});
var host = builder.Build(); var host = builder.Build();
host.Run(); host.Run();

View File

@ -131,10 +131,8 @@ namespace MusicStore
//This method is invoked when ASPNETCORE_ENVIRONMENT is 'Development' or is not defined //This method is invoked when ASPNETCORE_ENVIRONMENT is 'Development' or is not defined
//The allowed values are Development,Staging and Production //The allowed values are Development,Staging and Production
public void ConfigureDevelopment(IApplicationBuilder app, ILoggerFactory loggerFactory) public void ConfigureDevelopment(IApplicationBuilder app)
{ {
loggerFactory.AddConsole(minLevel: LogLevel.Information);
// StatusCode pages to gracefully handle status codes 400-599. // StatusCode pages to gracefully handle status codes 400-599.
app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage"); app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage");
@ -149,10 +147,8 @@ namespace MusicStore
//This method is invoked when ASPNETCORE_ENVIRONMENT is 'Staging' //This method is invoked when ASPNETCORE_ENVIRONMENT is 'Staging'
//The allowed values are Development,Staging and Production //The allowed values are Development,Staging and Production
public void ConfigureStaging(IApplicationBuilder app, ILoggerFactory loggerFactory) public void ConfigureStaging(IApplicationBuilder app)
{ {
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
// StatusCode pages to gracefully handle status codes 400-599. // StatusCode pages to gracefully handle status codes 400-599.
app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage"); app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage");
@ -163,10 +159,8 @@ namespace MusicStore
//This method is invoked when ASPNETCORE_ENVIRONMENT is 'Production' //This method is invoked when ASPNETCORE_ENVIRONMENT is 'Production'
//The allowed values are Development,Staging and Production //The allowed values are Development,Staging and Production
public void ConfigureProduction(IApplicationBuilder app, ILoggerFactory loggerFactory) public void ConfigureProduction(IApplicationBuilder app)
{ {
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
// StatusCode pages to gracefully handle status codes 400-599. // StatusCode pages to gracefully handle status codes 400-599.
app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage"); app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage");

View File

@ -92,10 +92,8 @@ namespace MusicStore
}); });
} }
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app)
{ {
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage"); app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage");
// Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the // Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the

View File

@ -111,10 +111,8 @@ namespace MusicStore
}); });
} }
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app)
{ {
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage"); app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage");
// Display custom error page in production when error occurs // Display custom error page in production when error occurs