diff --git a/LCU.API.Internal.CoreSoapApiWrapper/LCU.API.Internal.CoreSoapApiWrapper/Global.asax.cs b/LCU.API.Internal.CoreSoapApiWrapper/LCU.API.Internal.CoreSoapApiWrapper/Global.asax.cs index 8a0ea29..02066d5 100644 --- a/LCU.API.Internal.CoreSoapApiWrapper/LCU.API.Internal.CoreSoapApiWrapper/Global.asax.cs +++ b/LCU.API.Internal.CoreSoapApiWrapper/LCU.API.Internal.CoreSoapApiWrapper/Global.asax.cs @@ -1,5 +1,8 @@ using Serilog; +using Serilog.Events; using System.Net; +using System.Configuration; +using System.IO; using System.Web.Http; using System.Web.Mvc; using System.Web.Routing; @@ -9,7 +12,7 @@ namespace LCU.API.Internal.CoreSoapApiWrapper { public class WebApiApplication : System.Web.HttpApplication { - protected void Application_Start() + protected void Application_Start() { AreaRegistration.RegisterAllAreas(); IocBootstrapper.Run(); @@ -24,8 +27,22 @@ namespace LCU.API.Internal.CoreSoapApiWrapper ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; + var seqApiKey = ConfigurationManager.AppSettings["serilog:write-to:Seq.apiKey"]; + try + { + seqApiKey = File.ReadAllText("/vault/secrets/core-soap-api-wrapper-api-seq-api-key.json").Trim(); + } + catch (IOException) + { + // Fall back to the configured app setting when the secret file is not mounted. + } + catch (UnauthorizedAccessException) + { + // Fall back to the configured app setting when the secret file is not readable. + } + Log.Logger = new LoggerConfiguration() - .ReadFrom.AppSettings() + .MinimumLevel.Verbose() .Enrich.WithMachineName() .Enrich.WithEnvironmentUserName() .Enrich.WithHttpRequestClientHostIP() @@ -38,6 +55,9 @@ namespace LCU.API.Internal.CoreSoapApiWrapper .Enrich.WithWebApiControllerName() .Enrich.WithWebApiRouteData() .Enrich.WithWebApiRouteTemplate() + .WriteTo.Console() + .WriteTo.File(ConfigurationManager.AppSettings["serilog:write-to:File.path"], rollingInterval: RollingInterval.Day, retainedFileCountLimit: 4) + .WriteTo.Seq(ConfigurationManager.AppSettings["serilog:write-to:Seq.serverUrl"], LogEventLevel.Information, 1000, null, seqApiKey) .CreateLogger(); Log.Information("Core Soap Api Wrapper Starting Up");