refactor: Entfernen des App Loggers und Implementierung des ILogger-Interfaces; Konfiguration der API für NLog

- App Logger entfernt und durch die Implementierung des `ILogger`-Interfaces ersetzt, um eine konsistente Logging-Architektur zu gewährleisten.
- API für die Nutzung von NLog konfiguriert, um eine leistungsstarke und flexible Logging-Lösung bereitzustellen.
- Konfigurationsdateien und Setup-Anpassungen für die Integration von NLog in die API vorgenommen.
This commit is contained in:
Developer 02
2024-08-27 19:41:12 +02:00
parent cfd163a7a7
commit 197db1e08b
79 changed files with 247 additions and 724 deletions

View File

@@ -1,5 +1,4 @@
using DAL;
using HRD.AppLogger;
using HRD.WebApi;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@@ -23,17 +22,10 @@ using NSwag;
using System.Linq;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.AspNetCore.Mvc;
using NLog;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) =>
{
ILoggerManager logger = new LoggerManager();
logger.LogException((Exception)unhandledExceptionEventArgs.ExceptionObject, "Application closed due to exception.");
NLog.LogManager.Flush();
};
ILoggerManager logger = new LoggerManager();
logger.LogWarn($"[Start WebApi Server] BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}; TargetFrameworkName: {AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName}");
var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
try
{
var builder = WebApplication.CreateBuilder(args);
@@ -62,9 +54,7 @@ try
builder.Services.ConfigureJWT(StaffDBServer.Extends.JwtMiddlewareOptionsHelper.GetJwtMiddlewareOptions()); ;
builder.Services.ConfigureDAL(WebApiMiddlewareOptionsHelper.GetWebApiMiddlewareOptions());
builder.Services.AddSingleton<ILoggerManager, LoggerManager>();
//SWAGGER
builder.Services.AddSwaggerDocument(config =>
{
@@ -165,7 +155,7 @@ try
}
catch (Exception ex)
{
logger.LogException(ex, "Stopped program because of exception");
logger.Log(NLog.LogLevel.Error, ex, $"Stopped program because of exception\n{ex.Message}");
throw;
}
finally