Package | Version | Popularity |
---|---|---|
Gleeman.EffectiveLogger.MongoDB |
dotnet
CLI
$ dotnet add package Gleeman.EffectiveLogger.MongoDB --version 2.0.0
using Gleeman.EffectiveLogger.MongoDB.Configurations;
builder.Services.AddMongoDbLog(opt =>
{
opt.WriteToConsole = true; // true or false
opt.WriteToFile = true; // true or false
opt.FilePath = "File Path here";
opt.FileName = "Api";
opt.MongoConnection = "mongodb://localhost:27017";
opt.CollectionName = "Logs";
opt.DatabaseName = "ApiLog";
});
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly IEffectiveLogger<WeatherForecastController> _logger;
public WeatherForecastController(IEffectiveLogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
_logger.Info($"{Request.Path} - {Request.Method} - {Response.StatusCode}");
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}