1
I am studying . Net Core 2 and I have a question. I am wanting to log error in my Repository layer and only saw example in Controller. Some specific reason for this?
Follows my codes:
appsettings.json
{
   "ConnectionStrings": {
   "DefaultConnection": "Server=FAYOL\\SQLEXPRESS;Database=Pagamento;Trusted_Connection=True;MultipleActiveResultSets=true"
      },
      "Logging": {
        "IncludeScopes": false,
        "Debug": {
          "LogLevel": {
            "Default": "Warning"
          }
        },
        "Console": {
          "LogLevel": {
            "Default": "Warning"
          }
        }
      }
    }
Program.Cs
public static void Main(string[] args)
{
    BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
  WebHost.CreateDefaultBuilder(args)
     .UseStartup<Startup>()
     .ConfigureLogging((hostingContext, logging) =>
     {
                        logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                        logging.AddConsole();
                        logging.AddDebug();
     })
     .Build();
Lojarepository.Cs
private readonly Contexto _context;
private readonly ILogger _logger;
public LojaRepository(Contexto context, ILogger<LojaRepository> logger)
{
   _context = context;
   _logger = logger;
}
public void Salvar(Loja loja)
{
    _logger.LogInformation("Teste de log para salvar");
}
Where I tell you what file name and where to save?
Thank you
You have to install a package that is a type of Provider that saves the logs of your application to a txt file: https://github.com/fulviocanducci/serilog-extensions-logging-file take a look at this link!
– novic