Gleeman Effective Logger File and/or Console

Package Version Popularity
Gleeman.EffectiveLogger.ConsoleFile NuGet Nuget

dotnet CLI

$ dotnet add package Gleeman.EffectiveLogger.ConsoleFile --version 2.0.1

Program.cs

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";
});

OR

appsettings.json

"LogSettings": {
  "WriteToConsole": true, // true or false
  "WriteToFile": true, // // true or false
  "FilePath": "File path is here",
  "FileName": "File name is here"
}

Program.cs

using Gleeman.EffectiveLogger.ConsoleFile.Configurations;
builder.Services.AddConsoleFileLog(builder.Configuration);

Controller

 [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();
     }
 }

Console

Console

File

File