[英]Serilog not writing to text file from console app
I have a Logging.Core
class library with the following simple class.我有一个
Logging.Core
类库,其中包含以下简单类。 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:然后在我的控制台应用程序的
Program
类中,我尝试写入日志条目:
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".当我检查我的输出文件夹时,我看到
log.txt
已创建,但它应该至少有一个条目“应用程序启动已开始”时为空。 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:控制台应用程序完全按预期运行,进程以代码 0 退出。两个项目都是 .NET 5.0,日志库具有以下 Nuget 包:
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.