Skip to content

Instantly share code, notes, and snippets.

@Rajdeep-Das
Created September 10, 2022 11:53
Show Gist options
  • Save Rajdeep-Das/43b6602bf586f4bcdd004dae9831fba7 to your computer and use it in GitHub Desktop.
Save Rajdeep-Das/43b6602bf586f4bcdd004dae9831fba7 to your computer and use it in GitHub Desktop.
using WatchLogger;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddWatchLoggerServices(opt =>
{
opt.SetExternalDbConnString = builder.Configuration["RedisConnectionString"];
});
var app = builder.Build();
// Use Excetion Logger Top To Catch Early Eception
// app.UseWatchLoggerExceptionLogger();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateTime.Now.AddDays(index),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast");
app.MapGet("/exception", () => {
throw new Exception("Test Exception Method");
});
// Custom Logger
app.UseWatchLogger();
app.Run();
internal record WeatherForecast(DateTime Date, int TemperatureC, string Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment