Skip to content

Commit

Permalink
feat: Debuggery (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybeeelsdon authored Jan 16, 2024
1 parent 7d9f026 commit ff21baa
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions src/TRE-UI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@
using Newtonsoft.Json;

var builder = WebApplication.CreateBuilder(args);
ConfigurationManager configuration = builder.Configuration;
IWebHostEnvironment environment = builder.Environment;

Log.Logger = CreateSerilogLogger(configuration, environment);
Log.Information("TRE-UI logging LastStatusUpdate.");
try{

builder.Host.UseSerilog();
IdentityModelEventSource.ShowPII = true;

builder.Services.AddControllersWithViews().AddNewtonsoftJson(options => {
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
options.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
}).AddRazorRuntimeCompilation();

ConfigurationManager configuration = builder.Configuration;
IWebHostEnvironment environment = builder.Environment;

string AppName = typeof(Program).Module.Name.Replace(".dll", "");

Log.Logger = CreateSerilogLogger(configuration, environment);
Log.Information("TRE-UI logging LastStatusUpdate.");




Expand Down Expand Up @@ -272,21 +276,7 @@
// //app.UseHsts();
//}

Serilog.ILogger CreateSerilogLogger(ConfigurationManager configuration, IWebHostEnvironment environment)
{
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
var seqApiKey = configuration["Serilog:SeqApiKey"];

return new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.WithProperty("ApplicationContext", environment.ApplicationName)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.Seq(seqServerUrl, apiKey: seqApiKey)
.ReadFrom.Configuration(configuration)
.CreateLogger();

}

//removed to stop redirection
//app.UseHttpsRedirection();
Expand Down Expand Up @@ -316,6 +306,33 @@ Serilog.ILogger CreateSerilogLogger(ConfigurationManager configuration, IWebHost

app.Run();

}
catch (Exception ex)
{
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", "TreUI");
}
finally
{
Log.Information("Stopping web ui V3 ({ApplicationContext})...", "TreUI");
Log.CloseAndFlush();
}

Serilog.ILogger CreateSerilogLogger(ConfigurationManager configuration, IWebHostEnvironment environment)
{
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
var seqApiKey = configuration["Serilog:SeqApiKey"];

return new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.WithProperty("ApplicationContext", environment.ApplicationName)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.Seq(seqServerUrl, apiKey: seqApiKey)
.ReadFrom.Configuration(configuration)
.CreateLogger();

}

#region SameSite Cookie Issue - https://community.auth0.com/t/correlation-failed-unknown-location-error-on-chrome-but-not-in-safari/40013/7

void CheckSameSite(HttpContext httpContext, CookieOptions options)
Expand Down

0 comments on commit ff21baa

Please sign in to comment.