将日志写入不同的文件 serilog .net core WebApi

问题描述 投票:0回答:0

我正在尝试配置 serilog 以写入多个文件,但没有任何运气。使用此配置,过滤器根本不起作用。有什么建议吗?

"Serilog": {
    "Using": [ "Serilog.Sinks.File" ],
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Default": "Information",
        "Microsoft.AspNetCore": "Warning",
        "Microsoft.Hosting.Lifetime": "Information",
        "Microsoft.Extensions.Hosting.Internal.Host": "Debug"
      }
    },
    "WriteTo": [
      {
        "Name": "Logger",
        "Args": {
          "configureLogger": {
            "Filter": [
              {
                "Name": "ByIncludingOnly",
                "Args": {
                  "expression": "(@Level = 'Error' or @Level = 'Fatal' or @Level = 'Warning')"
                }
              }
            ],
            "WriteTo": [
              {
                "Name": "File",
                "Args": {
                  "path": "../logs/error_.log",
                  "outputTemplate": "{Timestamp:o} [{Level:u3}] ({SourceContext}) {Message}{NewLine}{Exception}",
                  "rollingInterval": "Day"
                }
              }
            ]
          }
        }
      },

我尝试在单独的文件中记录不同的日志,但配置无法过滤日志。

.net asp.net-core-webapi serilog serilog-exceptions serilog-filter
© www.soinside.com 2019 - 2024. All rights reserved.