SharpRSS/SharpRSS.API/Program.cs

52 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.IO;
2023-09-03 00:13:02 +02:00
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;
2023-09-03 00:13:02 +02:00
2023-09-10 21:32:25 +02:00
SetupSerilog();
2023-09-03 00:13:02 +02:00
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddSerilog();
2023-09-03 00:13:02 +02:00
// 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();
2023-09-10 21:32:25 +02:00
builder.Services.AddScoped<AuthService>();
builder.Services.AddScoped<SharpRssService>();
2023-09-03 00:13:02 +02:00
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));
}