我正在尝试配置Serilog将日志写入多个文件,但始终无法成功。使用此配置只会将日志写入第二个文件?
{
"AllowedHosts": "*",
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "c:\\temp\\audit-.log",
"rollingInterval": "Day",
"restrictedToMinimumLevel": "Information"
}
},
{
"Name": "File",
"Args": {
"path": "c:\\temp\\error-.log",
"rollingInterval": "Day",
"restrictedToMinimumLevel": "Error"
}
}
]
}
}
是否有办法从appsettings.json中加载多个具有不同配置的记录器到软件中。类似这样的内容?
var errorLogConfiguration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
.AddEnvironmentVariables()
.Build();
_log = new LoggerConfiguration()
.ReadFrom
.Configuration(errorLogConfiguration)
.CreateLogger();