I'm trying to use Serilog's AddFile by way of LoggerFactory but I can't get it to do anything.
This is my appsettings.json, unchanged from the getting started guide.
Here is what I have:
IConfiguration Configuration = new ConfigurationBuilder()
//.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "Logs"))
.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "Properties", "appsettings.json"), optional: false, reloadOnChange: false)
//.AddEnvironmentVariables()
//.AddCommandLine(args)
.Build();
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => {
builder
.AddConfiguration(Configuration.GetSection("Logging"))
.AddConsole()
.AddDebug()
.AddFile("log.txt"); //Configuration.GetSection("Logging"));
});
ILogger<Program> logger = loggerFactory.CreateLogger<Program>();
logger.LogTrace("Trace");
logger.LogInformation("Information");
logger.LogDebug("Debug");
logger.LogError("Error");
logger.LogCritical("Critical");
I see output in the console. I receive no errors. Even with the suggested addition of:
Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));
From: https://github.com/serilog/serilog/wiki/Debugging-and-Diagnostics