From cbd3accf72ff97852fd2fdb957fc74c696e20e52 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Mon, 10 Mar 2025 15:42:22 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Logging=20f=C3=BCr=20unerwartete=20Ausn?= =?UTF-8?q?ahmen=20hinzugef=C3=BCgt,=20um=20eine=20bessere=20Fehlerverfolg?= =?UTF-8?q?ung=20und=20Probleml=C3=B6sung=20zu=20gew=C3=A4hrleisten.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/Program.cs b/Program.cs index 9527f99..ea89877 100644 --- a/Program.cs +++ b/Program.cs @@ -6,27 +6,36 @@ using Ocelot.Middleware; var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger(); logger.Info("Logging initialized."); -var builder = WebApplication.CreateBuilder(args); +try +{ + var builder = WebApplication.CreateBuilder(args); -// Make sure to add the Ocelot configuration file -var suffix = builder.Environment.IsDevelopment() ? ".Development" : ""; -builder.Configuration.AddJsonFile($"ocelot{suffix}.json"); + // Make sure to add the Ocelot configuration file + var suffix = builder.Environment.IsDevelopment() ? ".Development" : ""; + builder.Configuration.AddJsonFile($"ocelot{suffix}.json"); -// Add Ocelot services -builder.Services.AddOcelot(); + // Add Ocelot services + builder.Services.AddOcelot(); -var app = builder.Build(); + var app = builder.Build(); -app.UseHttpsRedirection(); -app.UseRouting(); -app.UseAuthorization(); + app.UseHttpsRedirection(); + app.UseRouting(); + app.UseAuthorization(); -// Use Ocelot middleware in an appropriate way -app.UseEndpoints(endpoints => -{ - endpoints.MapControllers(); -}); + // Use Ocelot middleware in an appropriate way + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); -app.UseOcelot().Wait(); + app.UseOcelot().Wait(); -app.Run(); + app.Run(); + +} +catch(Exception ex) +{ + logger.Error(ex, "Stopped program because of exception."); + throw; +} \ No newline at end of file