首页 新闻 会员 周边

CentOS7部署ASP.NET Core 6时Serilog日志配置无效

0
悬赏园豆:5 [已关闭问题] 关闭于 2023-03-06 22:18

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

悦峯的主页 悦峯 | 菜鸟二级 | 园豆:223
提问于:2023-02-18 16:18
< >
分享
所有回答(1)
0

https://stackoverflow.com/questions/70127316/serilog-does-not-generate-logs-to-console-or-file-when-application-is-published

配置添加:
"Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Async"],

悦峯 | 园豆:223 (菜鸟二级) | 2023-03-06 22:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册