DigitalData.Gateway/Program.cs
Developer 02 6ade388cd7 Enhance logging configuration in Program.cs
Initialized logging by clearing providers, setting minimum
level to Trace, and configuring NLog as the logging provider.
2025-05-09 23:20:27 +02:00

42 lines
1020 B
C#

using NLog;
using NLog.Web;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
logger.Info("Logging initialized.");
try
{
var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
builder.Logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
builder.Host.UseNLog();
// 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();
var app = builder.Build();
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
// Use Ocelot middleware in an appropriate way
app.MapControllers();
app.UseOcelot().Wait();
app.Run();
}
catch(Exception ex)
{
logger.Error(ex, "Stopped program because of exception.");
throw;
}