I have a Logging.Core
class library with the following simple class. My aim is to share one configured logger between all other projects in the solution:
public static class Logging
{
public static void Configure()
{
ILogger logger = new LoggerConfiguration()
.WriteTo.File(path: "log.txt")
.CreateLogger();
Log.Logger = logger;
}
}
Then in my console app's Program
class, I try to write log entries:
static void Main(string[] args)
{
Logging.Core.Logging.Configure();
Log.Debug("Application startup has begun");
var dbPath = "dalbuilder.db";
if (!File.Exists(dbPath))
{
DalBuilderDb.CreateDbTables();
Log.Information("Created new Sqlite database file: {filePath}", dbPath);
}
DalSourceModel.LoadModelTables();
Log.CloseAndFlush();
}
When I check my output folder I see log.txt
has been created but is empty when it should have at least one entry, "Application startup has begun". The console app runs exactly as expected and the process exits with code 0. Both projects are .NET 5.0, and the logging library has the following Nuget packages:
Serilog (2.10.0)
Serilog.Sinks.File (4.1.0)
Wondering if this is a minimum level issue. Try :-
ILogger logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.File(path: "log.txt")
.CreateLogger();