asp.net-core - Serilog 未在 Ubuntu 上写入文件

标签 asp.net-core ubuntu serilog

我已将网站部署到 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,但不知道我也必须重新启动服务

关于asp.net-core - Serilog 未在 Ubuntu 上写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68690955/

相关文章:

asp.net-core - 为自定义类型创建自定义模型绑定(bind)器

c# - 查看在 Asp.Net core 3 的 Controller 中找不到操作

c# - Serilog 请求记录最终记录在事件日志中

c# - 不使用 ASP.Net Core 2 中的迁移命令 Update-Database 创建数据库

linux - 自动将输入提供给 Linux 命令行

linux - 如何从 bash 从最新到最旧的进程杀死进程

linux - 在 apache 中运行 perl 脚本时出现 403 错误

c# - 使用 Serilog for .NET 将日志写入 Excel 文件

.net-core - 从环境变量设置 Serilog 最低级别

entity-framework - Entity Framework 核心中的脚手架迁移