Improved configurability of Elmah and Serilog for the Indexer

This commit is contained in:
2025-06-15 23:38:58 +02:00
parent 9fa6704417
commit 4c7e92b6c6
2 changed files with 15 additions and 4 deletions

View File

@@ -16,7 +16,7 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.WriteTo.File("logs/log-.txt", rollingInterval: RollingInterval.Day) // Output files with daily rolling .ReadFrom.Configuration(builder.Configuration)
.CreateLogger(); .CreateLogger();
builder.Logging.AddSerilog(); builder.Logging.AddSerilog();
builder.Services.AddHttpContextAccessor(); builder.Services.AddHttpContextAccessor();
@@ -28,7 +28,7 @@ builder.Services.AddHealthChecks()
builder.Services.AddElmah<XmlFileErrorLog>(Options => builder.Services.AddElmah<XmlFileErrorLog>(Options =>
{ {
Options.LogPath = "~/logs"; Options.LogPath = builder.Configuration.GetValue<string>("EmbeddingsearchIndexer:Elmah:LogFolder") ?? "~/logs";
}); });
var app = builder.Build(); var app = builder.Build();
@@ -39,7 +39,6 @@ app.Use(async (context, next) =>
{ {
if (context.Request.Path.StartsWithSegments("/elmah")) if (context.Request.Path.StartsWithSegments("/elmah"))
{ {
var remoteIp = context.Connection.RemoteIpAddress?.ToString(); var remoteIp = context.Connection.RemoteIpAddress?.ToString();
bool blockRequest = allowedIps is null bool blockRequest = allowedIps is null
|| remoteIp is null || remoteIp is null

View File

@@ -5,12 +5,24 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": "Information",
"WriteTo": [
{ "Name": "Console" },
{ "Name": "File", "Args": { "path": "logs/log.txt", "rollingInterval": "Day", "retainedFileCountLimit": 7 } }
],
"Properties": {
"Application": "Indexer"
}
},
"EmbeddingsearchIndexer": { "EmbeddingsearchIndexer": {
"Elmah": { "Elmah": {
"AllowedHosts": [ "AllowedHosts": [
"127.0.0.1", "127.0.0.1",
"::1" "::1"
] ],
"LogFolder": "./logs"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*"