Files
monorepo/LCU.API.Internal.CoreSoapApiWrapper/LCU.API.Internal.CoreSoapApiWrapper/Global.asax.cs
T
2026-04-07 14:04:08 +00:00

67 lines
2.6 KiB
C#

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;
using LCU.API.Internal.CoreSoapApiWrapper.App_Start;
namespace LCU.API.Internal.CoreSoapApiWrapper
{
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
IocBootstrapper.Run();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings
.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
GlobalConfiguration.Configuration.Formatters
.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
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()
.MinimumLevel.Verbose()
.Enrich.WithMachineName()
.Enrich.WithEnvironmentUserName()
.Enrich.WithHttpRequestClientHostIP()
.Enrich.WithHttpRequestClientHostName()
.Enrich.WithHttpRequestRawUrl()
.Enrich.WithHttpRequestType()
.Enrich.WithHttpRequestUrl()
.Enrich.WithHttpRequestUrlReferrer()
.Enrich.WithWebApiActionName()
.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");
}
}
}