renis-backend/Program.cs

36 lines
1.1 KiB
C#
Raw Normal View History

2024-09-07 08:06:51 +00:00
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
2024-09-07 09:13:28 +00:00
configureLogging();
2024-09-07 08:06:51 +00:00
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.Run();
2024-09-07 08:59:23 +00:00
void configureLogging(){
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json",optional:false,reloadOnChange:true).Build();
Console.WriteLine(environment);
Console.WriteLine(configuration);
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.WriteTo.Debug()
.WriteTo.Console()
.Enrich.WithProperty("Environment",environment)
.ReadFrom.Configuration(configuration)
.CreateLogger();
}