You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

using CoreAgent.API;
using CoreAgent.Domain.Interfaces.Network;
using CoreAgent.Domain.Models.System;
using CoreAgent.Infrastructure.Logging;
using Serilog;
using System;
using System.Text.Json;
var builder = WebApplication.CreateBuilder(args);
try
{
// 第一步:添加所有配置
builder.AddConfigurations();
// 第二步:创建Startup实例
var startup = builder.CreateStartup();
// 第三步:配置服务
startup.ConfigureServices(builder.Services);
var app = builder.Build();
// 配置中间件
startup.Configure(app);
// 配置Swagger
app.ConfigureSwagger();
Log.Information("Application startup completed");
// 注册应用程序生命周期事件处理器
app.RegisterApplicationLifetimeHandlers();
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Application failed to start: {Message}", ex.Message);
// 记录详细的启动失败信息
var errorDetails = new
{
Message = ex.Message,
StackTrace = ex.StackTrace,
Source = ex.Source,
InnerException = ex.InnerException?.Message
};
Log.Fatal("Startup failure details: {Details}", JsonSerializer.Serialize(errorDetails));
// 确保所有日志都被写入
Log.CloseAndFlush();
// 使用非零退出码表示错误
Environment.Exit(1);
}