Created
September 14, 2022 22:32
-
-
Save otaviolarrosa/6ada2b14b9c653338e228279f4f4c023 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Application.Extensions; | |
using Consumers; | |
using Infrastructure.Extensions; | |
using Producers; | |
using Serilog; | |
using StreamNet; | |
var builder = WebApplication.CreateBuilder(args); | |
Log.Logger = new LoggerConfiguration() | |
.MinimumLevel.Debug() | |
.Enrich.WithCorrelationId() //Aqui, pedimos para o Serilog utilizar a feature de correlation Id. | |
.Enrich.WithCorrelationIdHeader() //Aqui, pedimos para utilizar o correlation Id, de quem solicitou a chamada na requisição HTTP, para que o trace fique ainda mais rico, com os logs do frontend. | |
.WriteTo.Console(outputTemplate: "[{CorrelationId} - {Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}") //Aqui, formatamos um template para formatação dos logs padronizados, à fim de facilitar a leitura. | |
.CreateLogger(); | |
builder.Host.UseSerilog(); //Adicionamos o Serilog dentro do Host do nosso serviço | |
builder.Services.AddHttpContextAccessor(); | |
builder.Services.AddSingleton(builder.Logging); | |
builder.Services.AddControllers(); | |
builder.Services.AddEndpointsApiExplorer(); | |
builder.Services.AddSwaggerGen(); | |
builder.Services.RegisterApplicationDependencies(builder.Configuration); | |
builder.Services.RegisterInfrastructureDependencies(builder.Configuration); | |
builder.Services.AddProducers(); | |
builder.Services.AddConsumers(); | |
builder.Services.AddTopicManagement(); | |
var app = builder.Build(); | |
app.RunMigrations(); | |
// Configure the HTTP request pipeline. | |
if (app.Environment.IsDevelopment()) | |
{ | |
app.UseSwagger(); | |
app.UseSwaggerUI(); | |
} | |
app.UseAuthorization(); | |
app.MapControllers(); | |
app.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment