VS2022调试,本地win10运行正常;部署到服务器上就不会产出日志文件。
只有.Net6会,同样情况3.1不会出现。
类似情况:https://cloud.tencent.com/developer/ask/sof/1058879
# appsettings.json 截取部分
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"System": "Information",
"Microsoft": "Information"
}
},
"WriteTo": [
{
"Name": "Async", // Serilog.Sinks.Async
"Args": {
"Configure": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:HH:mm:ss.fff} [{Level:u3}] {SourceContext}{NewLine}{Message}{NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"path": "Logs/log-.txt",
"rollingInterval": "Day"
}
}
]
}
}
]
},
其他代码
# Program.cs
builder.Host.UseSerilog((ctx, lc) => lc.ReadFrom.Configuration(ctx.Configuration));
# 相关包
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
用此项目生成也是一样:
https://github.com/datalust/dotnet6-serilog-example
配置添加:
"Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Async"],