update .net, setup modern logging
Some checks failed
Build and Publish / Build Yale Access Backend (pull_request) Failing after 1m28s
Build and Publish / Push Yale Access Backend Docker Image (pull_request) Has been skipped
Build and Publish / Build Yale Access Frontend (pull_request) Successful in 1m42s
Build and Publish / Push Yale Access Frontend Docker Image (pull_request) Has been skipped
Some checks failed
Build and Publish / Build Yale Access Backend (pull_request) Failing after 1m28s
Build and Publish / Push Yale Access Backend Docker Image (pull_request) Has been skipped
Build and Publish / Build Yale Access Frontend (pull_request) Successful in 1m42s
Build and Publish / Push Yale Access Frontend Docker Image (pull_request) Has been skipped
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using OpenTelemetry.Logs;
|
||||
using YaleAccess.Data;
|
||||
using YaleAccess.Models.Options;
|
||||
using YaleAccess.Services;
|
||||
@@ -10,15 +9,25 @@ using YaleAccess.Services.Interfaces;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Create the bootstraper logger
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console()
|
||||
.CreateLogger();
|
||||
|
||||
try
|
||||
{
|
||||
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
|
||||
|
||||
builder.Logging.AddOpenTelemetry(logging =>
|
||||
{
|
||||
logging.IncludeFormattedMessage = true;
|
||||
logging.IncludeScopes = true;
|
||||
|
||||
if (useOtlpExporter)
|
||||
{
|
||||
logging.AddOtlpExporter();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("OTEL_EXPORTER_OTLP_ENDPOINT is not set. Skipping OTLP exporter configuration.");
|
||||
}
|
||||
});
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers();
|
||||
|
||||
@@ -41,13 +50,6 @@ try
|
||||
|
||||
// Get a copy of the configuration
|
||||
IConfiguration configuration = builder.Configuration;
|
||||
string logLocation = configuration["LogLocation"] ?? "Log.txt";
|
||||
|
||||
// Setup the application logger
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Error)
|
||||
.WriteTo.File(logLocation, rollingInterval: RollingInterval.Day)
|
||||
.CreateLogger();
|
||||
|
||||
// Configure the DI services
|
||||
builder.Services.AddScoped<SMSService>();
|
||||
@@ -100,9 +102,6 @@ try
|
||||
};
|
||||
});
|
||||
|
||||
// Setup logging flow
|
||||
builder.Host.UseSerilog();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Create the database if it doesn't exist
|
||||
@@ -144,11 +143,7 @@ catch (Exception ex)
|
||||
// Ignore host aborted exceptions caused by build checks
|
||||
if (ex is not HostAbortedException)
|
||||
{
|
||||
Log.Fatal(ex, "Host terminated unexpectedly");
|
||||
Console.WriteLine("Host terminated unexpectedly");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
Reference in New Issue
Block a user