using System; using System.IO; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Serilog; using Serilog.Formatting.Compact; using SharpRSS.API.Data; using ToolQit; using ToolQit.Logging.Serilog; SetupSerilog(); var builder = WebApplication.CreateBuilder(args); builder.Logging.AddSerilog(); // 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(); builder.Services.AddScoped(); builder.Services.AddScoped(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run(); void SetupSerilog() { LoggerConfiguration _logConfig = new LoggerConfiguration() .Enrich.With(new LogEnricher()) .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} - {Sender} | {Level:u3}] {Message:lj}{NewLine}{Exception}") .WriteTo.File(new CompactJsonFormatter(), Path.Combine(Environment.CurrentDirectory, "logs", "log_.json"), rollingInterval: RollingInterval.Day); Log.Logger = _logConfig.CreateLogger(); LogManager.RegisterAdapter(new SerilogAdapter(Log.Logger)); }