From 5069814c4ff38f2912fc6875909304e463956143 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 23 Oct 2017 09:11:25 -0400 Subject: [PATCH] cleanup startup logging --- src/Api/Startup.cs | 35 +++++++++++++++++------------------ src/Billing/Startup.cs | 3 +-- src/Icons/Startup.cs | 10 +++++----- src/Identity/Startup.cs | 25 ++++++++++++------------- util/Mail/Program.cs | 13 +++++-------- 5 files changed, 40 insertions(+), 46 deletions(-) diff --git a/src/Api/Startup.cs b/src/Api/Startup.cs index e312dee0c..06c6b6c9a 100644 --- a/src/Api/Startup.cs +++ b/src/Api/Startup.cs @@ -149,28 +149,27 @@ namespace Bit.Api IApplicationLifetime appLifetime, GlobalSettings globalSettings) { - loggerFactory - .AddSerilog(env, appLifetime, globalSettings, (e) => + loggerFactory.AddSerilog(env, appLifetime, globalSettings, (e) => + { + var context = e.Properties["SourceContext"].ToString(); + if(e.Exception != null && (e.Exception.GetType() == typeof(SecurityTokenValidationException) || + e.Exception.Message == "Bad security stamp.")) { - var context = e.Properties["SourceContext"].ToString(); - if(e.Exception != null && (e.Exception.GetType() == typeof(SecurityTokenValidationException) || - e.Exception.Message == "Bad security stamp.")) - { - return false; - } + return false; + } - if(context.Contains(typeof(IpRateLimitMiddleware).FullName) && e.Level == LogEventLevel.Information) - { - return true; - } + if(context.Contains(typeof(IpRateLimitMiddleware).FullName) && e.Level == LogEventLevel.Information) + { + return true; + } - if(context.Contains("IdentityServer4.Validation.TokenRequestValidator")) - { - return e.Level > LogEventLevel.Error; - } + if(context.Contains("IdentityServer4.Validation.TokenRequestValidator")) + { + return e.Level > LogEventLevel.Error; + } - return e.Level >= LogEventLevel.Error; - }); + return e.Level >= LogEventLevel.Error; + }); // Default Middleware app.UseDefaultMiddleware(env); diff --git a/src/Billing/Startup.cs b/src/Billing/Startup.cs index d61f14bc3..5f34658fa 100644 --- a/src/Billing/Startup.cs +++ b/src/Billing/Startup.cs @@ -64,8 +64,7 @@ namespace Bit.Billing GlobalSettings globalSettings, ILoggerFactory loggerFactory) { - loggerFactory - .AddSerilog(env, appLifetime, globalSettings, (e) => e.Level >= LogEventLevel.Error); + loggerFactory.AddSerilog(env, appLifetime, globalSettings, (e) => e.Level >= LogEventLevel.Error); if(env.IsDevelopment()) { diff --git a/src/Icons/Startup.cs b/src/Icons/Startup.cs index 6e61f5796..6859d91f0 100644 --- a/src/Icons/Startup.cs +++ b/src/Icons/Startup.cs @@ -46,17 +46,17 @@ namespace Bit.Icons IHostingEnvironment env, TelemetryConfiguration telemetry) { + if(env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + try { telemetry.DisableTelemetry = true; } catch { } - if(env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - app.UseResponseCaching(); app.UseMvc(); } diff --git a/src/Identity/Startup.cs b/src/Identity/Startup.cs index 3bd5a4ede..2aa4c5a89 100644 --- a/src/Identity/Startup.cs +++ b/src/Identity/Startup.cs @@ -72,22 +72,21 @@ namespace Bit.Identity IApplicationLifetime appLifetime, GlobalSettings globalSettings) { - loggerFactory - .AddSerilog(env, appLifetime, globalSettings, (e) => + loggerFactory.AddSerilog(env, appLifetime, globalSettings, (e) => + { + var context = e.Properties["SourceContext"].ToString(); + if(context.Contains("IdentityServer4.Validation.TokenRequestValidator")) { - var context = e.Properties["SourceContext"].ToString(); - if(context.Contains("IdentityServer4.Validation.TokenRequestValidator")) - { - return e.Level > LogEventLevel.Error; - } + return e.Level > LogEventLevel.Error; + } - if(context.Contains(typeof(IpRateLimitMiddleware).FullName) && e.Level == LogEventLevel.Information) - { - return true; - } + if(context.Contains(typeof(IpRateLimitMiddleware).FullName) && e.Level == LogEventLevel.Information) + { + return true; + } - return e.Level >= LogEventLevel.Error; - }); + return e.Level >= LogEventLevel.Error; + }); // Default Middleware app.UseDefaultMiddleware(env); diff --git a/util/Mail/Program.cs b/util/Mail/Program.cs index bacde93ac..046a176c2 100644 --- a/util/Mail/Program.cs +++ b/util/Mail/Program.cs @@ -1,4 +1,4 @@ -using System.IO; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; namespace Bit.Mail @@ -7,14 +7,11 @@ namespace Bit.Mail { public static void Main(string[] args) { - var host = new WebHostBuilder() - .UseKestrel() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() + WebHost + .CreateDefaultBuilder(args) .UseStartup() - .Build(); - - host.Run(); + .Build() + .Run(); } } }