Created
September 10, 2022 11:53
-
-
Save Rajdeep-Das/43b6602bf586f4bcdd004dae9831fba7 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 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