Fix logging and remove incorrect swagger configuration

هذا الالتزام موجود في:
2025-10-07 06:39:17 +03:00
الأصل a99026ee02
التزام 9fb797f6d4
5 ملفات معدلة مع 1462 إضافات و443 حذوفات

عرض الملف

@@ -17,13 +17,13 @@ builder.Logging.AddSimpleConsole(options =>
});
// Serilog file path
var logFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Logs", $"app-log{DateTime.Now:yyyyMMdd}.json");
var logFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Logs", "api.log");
Directory.CreateDirectory(Path.GetDirectoryName(logFilePath)!);
// Serilog configuration
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File(new JsonFormatter(), logFilePath, rollingInterval: RollingInterval.Day)
.WriteTo.File(new JsonFormatter(), logFilePath, rollOnFileSizeLimit: true)
.CreateLogger();
builder.Host.UseSerilog();
@@ -34,14 +34,6 @@ builder.Services.AddDbContext<AppDbContext>(options =>
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
// Swagger + XML Comments
builder.Services.AddSwaggerGen(c =>
{
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
var app = builder.Build();
// Database seeding
@@ -54,7 +46,7 @@ using (var scope = app.Services.CreateScope())
if (File.Exists(jsonPath))
{
var json = File.ReadAllText(jsonPath);
var wonders = System.Text.Json.JsonSerializer.Deserialize<List<Wonder>>(json) ?? new();
var wonders = System.Text.Json.JsonSerializer.Deserialize<List<Wonder>>(json) ?? [];
db.Wonders.AddRange(wonders);
db.SaveChanges();
}
@@ -69,14 +61,6 @@ using (var scope = app.Services.CreateScope())
var logger = app.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Wonders API application started successfully at {time}", DateTime.Now);
// Swagger Middleware
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Wonders API V1");
options.DocumentTitle = "Wonders API Docs";
});
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();