Serilog 未在 Ubuntu 上写入文件

Serilog not writing to file on Ubuntu

我已将网站部署到 ubuntu 机器,但无法让 serilog 写入文件

这是我的:

在Program.cs中(省略不必要的部分):

 public static void Main(string[] args)
    {
        var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
        var configuration = new ConfigurationBuilder()
             .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
             .AddJsonFile($"appsettings.{environment}.json", optional: true)
             .AddEnvironmentVariables()
             .Build();

        Log.Logger = new LoggerConfiguration()
            .ReadFrom.Configuration(configuration)
            .CreateLogger();

还有:

return Host.CreateDefaultBuilder(args)
            
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder

                .UseUrls($"http://localhost:{port}")
                .UseStartup<Startup>();
            })
            .UseSerilog();

在我的 appsetting.PreProduction.json:

"Serilog": {
"MinimumLevel": "Information",
"WriteTo": [
  {
    "Name": "File",
    "Args": {
      "path": "/var/log/myapp/",
      "rollingInterval": "Day"
    }
  }
]

},

这适用于我的本地机器 Windows

 {
    "Name": "File",
    "Args": {
      "path": "c:\myapp\log.txt",
      "rollingInterval": "Day"
    }
  },

我需要做任何额外的许可吗?

我不得不重新启动服务:

sudo systemctl restart myapp.service

还必须设置权限:

mkdir /var/log/myapp/
chown apiuser:apiuser /var/log/myapp/
chmod 740 /var/log/myapp

我一直在重启nginx,但不知道我也必须重启服务