[英].net core console app - serilog write to bin/debug folder
i am using .net5 console app and set serilog to log to Logs/log.txt but instead of write to rootFolder/Logs/log.txt it write to bin/debug folder.我正在使用 .net5 控制台应用程序并将 serilog 设置为记录到 Logs/log.txt,但不是写入 rootFolder/Logs/log.txt,而是写入到 bin/debug 文件夹。
EDIT: I attach the code:编辑:我附上代码:
in the appsettings.json it looks like this:在 appsettings.json 它看起来像这样:
{
"Name": "File",
"Args": {
"path": "Logs\log.txt",
}
}
Program.cs程序.cs
static void Main(string[] args)
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("appSettings.json", true, true)
.Build();
var serviceCollection = new ServiceCollection()
.AddLogging(builder => builder.AddSerilog(
new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger()))
.BuildServiceProvider();
var logger = serviceCollection.GetService<ILogger<Program>>();
logger.LogInformation("hello from Serilog");
Console.ReadLine();
}
any idea please?有什么想法吗?
Try this in program.cs file在 program.cs 文件中试试这个
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithProperty("Application", "MyApp")
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("System", LogEventLevel.Warning)
.WriteTo.File("Logs/log.log",
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
rollingInterval: RollingInterval.Hour)
.CreateLogger();
And appsettings file和 appsettings 文件
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}, },
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.