Added Serilog logging, added Elmah error logging, added health checks

This commit is contained in:
2025-06-09 17:09:55 +02:00
parent 60bfcff539
commit ce168cf9e4
10 changed files with 246 additions and 36 deletions

View File

@@ -1,6 +1,11 @@
using Indexer;
using Indexer.Models;
using Indexer.Services;
using ElmahCore;
using ElmahCore.Mvc;
using Server;
using ElmahCore.Mvc.Logger;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
@@ -10,16 +15,32 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
Log.Logger = new LoggerConfiguration()
.WriteTo.File("logs/log-.txt", rollingInterval: RollingInterval.Day) // Output files with daily rolling
.CreateLogger();
builder.Logging.AddSerilog();
builder.Services.AddHttpContextAccessor();
builder.Services.AddSingleton<Client.Client>();
builder.Services.AddSingleton<WorkerCollection>();
builder.Services.AddHostedService<IndexerService>();
builder.Services.AddHealthChecks()
.AddCheck<WorkerHealthCheck>("WorkerHealthCheck");
builder.Services.AddElmah<XmlFileErrorLog>(Options =>
{
Options.LogPath = "~/logs";
});
var app = builder.Build();
app.UseElmah();
app.MapHealthChecks("/healthz");
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseElmahExceptionPage();
}
else
{