using Microsoft.Extensions.Configuration; using Serilog; using TelpoKafkaConsole.Model; using TelpoKafkaConsole.Service; using TelpoKafkaConsole.WebApi.Configs; using TelpoKafkaConsole.WebApi.Middleware; namespace TelpoKafkaConsole.WebApi { public class Program { public static void Main(string[] args) { //选择配置文件appsetting.json var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(config).Enrich.WithThreadInfo() .CreateLogger(); var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); #region 配置信息 builder.Services .Configure(builder.Configuration.GetSection("ServiceConfig")); #endregion builder.Services.AddSingleton(); builder.Host.UseSerilog(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseAuthorization(); app.UseMiddleware(); app.MapControllers(); app.Run(); } } }