Package | Version | Popularity |
---|---|---|
Gleeman.EffectiveLogger.ConsoleFile |
dotnet
CLI
$ dotnet add package Gleeman.EffectiveLogger.ConsoleFile --version 2.0.1
using Gleeman.EffectiveLogger.ConsoleFile.Configurations;
builder.Services.AddConsoleFileLog(settings =>
{
settings.WriteToFile = true;
settings.WriteToConsole = true;
settings.FilePath = "File path is here";
settings.FileName = "File name is here";
});
appsettings.json
"LogSettings": {
"WriteToConsole": true, // true or false
"WriteToFile": true, // // true or false
"FilePath": "File path is here",
"FileName": "File name is here"
}
using Gleeman.EffectiveLogger.ConsoleFile.Configurations;
builder.Services.AddConsoleFileLog(builder.Configuration);
[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} - Status: {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();
}
}