From 87d7262d0a1d76218fdcfd45aed42e9d17470db8 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Tue, 16 Jun 2026 09:28:39 +0200 Subject: [PATCH] Replace Logging with Serilog; add new configurations Replaced the `Logging` configuration in both `appsettings.json` and `appsettings.Development.json` with Serilog, enabling structured logging with configurable sinks and enrichment. Added `DocumentOperatorSettings` to manage temporary files and logging details. Introduced `RedisSettings` for Redis integration, including connection string and cache settings. Added `ApiKeySettings` to support tenant-specific API key validation with detailed configuration for each tenant. These changes improve logging, caching, and configuration management for better maintainability and extensibility. --- .../appsettings.Development.json | 18 ++++-- DocumentOperator.API/appsettings.json | 61 ++++++++++++++++++- 2 files changed, 72 insertions(+), 7 deletions(-) diff --git a/DocumentOperator.API/appsettings.Development.json b/DocumentOperator.API/appsettings.Development.json index 0c208ae..8901322 100644 --- a/DocumentOperator.API/appsettings.Development.json +++ b/DocumentOperator.API/appsettings.Development.json @@ -1,8 +1,16 @@ { - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Serilog": { + "MinimumLevel": { + "Default": "Debug" } + }, + + "DocumentOperatorSettings": { + "TempFolderPath": "C:\\Temp\\DocumentOperator\\Dev", + "EnableDetailedLogging": true + }, + + "RedisSettings": { + "ConnectionString": "localhost:6379" } -} +} \ No newline at end of file diff --git a/DocumentOperator.API/appsettings.json b/DocumentOperator.API/appsettings.json index 10f68b8..2922e0c 100644 --- a/DocumentOperator.API/appsettings.json +++ b/DocumentOperator.API/appsettings.json @@ -5,5 +5,62 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" -} + "AllowedHosts": "*", + + "Serilog": { + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft": "Warning", + "Microsoft.AspNetCore": "Warning", + "System": "Warning" + } + }, + "WriteTo": [ + { + "Name": "Console", + "Args": { + "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/log-.txt", + "rollingInterval": "Day", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ] + }, + + "DocumentOperatorSettings": { + "TempFolderPath": "C:\\Temp\\DocumentOperator", + "TempFileRetentionHours": 24, + "MaxPdfSizeMB": 50, + "EnableDetailedLogging": true + }, + + "RedisSettings": { + "ConnectionString": "localhost:6379", + "InstanceName": "DocumentOperator:", + "CacheExpirationMinutes": 60 + }, + + "ApiKeySettings": { + "EnableValidation": true, + "Keys": { + "customer-a-key-12345": { + "TenantId": "customer-a", + "TenantName": "Customer A GmbH", + "IsActive": true + }, + "customer-b-key-67890": { + "TenantId": "customer-b", + "TenantName": "Customer B AG", + "IsActive": true + } + } + } +} \ No newline at end of file