【问题标题】:Post Serilog logs to Rest api将 Serilog 日志发布到 Rest api
【发布时间】:2020-03-31 16:03:45
【问题描述】:

我想使用 Serilogger 将我的 .net 核心服务器的日志写入 Rest-api。我已经检查了几种方法,并通过提供我的 rest api 的 url 来尝试 Seq sink。但它不能有效地工作。 是否有任何休息api接收器?感谢您的帮助

"Serilog": {
    "Using": [ "Serilog", "Serilog.Sinks.Console", "Serilog.Sinks.Seq" ],
    "MinimumLevel": {
      "Default": "Verbose",
      "Override": {
        "System": "Information",
        "Microsoft": "Information",
        "Microsoft.EntityFrameworkCore": "Information"
      }
    },
    "WriteTo": [
      {
        "Name": "Seq",
        "Args": {
          "serverUrl": "http://localhost:6010",
          "apiKey": "none",
          "restrictedToMinimumLevel": "Verbose"
        }
      },
      {
        "Name": "Async",
        "Args": {
          "configure": [
            {
              "Name": "Console",
              "Args": {
                "restrictedToMinimumLevel": "Information"
              }
            }
          ]
        }
      }
    ],

【问题讨论】:

    标签: web-services asp.net-core serilog seq


    【解决方案1】:

    您可以尝试 Serilog.Sinks.Http,这是一个用于通过 HTTP 发送日志事件的 Serilog 接收器。

    以下是假设的 JSON 有效负载示例:

    {
      "events": [
        {
          "Timestamp": "2020-03-31T00:05:30.4899425-03:00",
          "Level": "Information",
          "MessageTemplate": "Logging {@Heartbeat} from {Computer}",
          "RenderedMessage": "Logging { UserName: \"augustoproiete\", UserDomainName: \"XLSTACK\" } from \"Workstation\"",
          "Properties": {
            "Heartbeat": {
              "UserName": "augustoproiete",
              "UserDomainName": "XLSTACK"
            },
            "Computer": "Workstation"
          }
        },
        {
          "Timestamp": "2020-03-31T00:09:12.4905685-03:00",
          "Level": "Information",
          "MessageTemplate": "Logging {@Heartbeat} from {Computer}",
          "RenderedMessage": "Logging { UserName: \"augustoproiete\", UserDomainName: \"XLSTACK\" } from \"Workstation\"",
          "Properties": {
            "Heartbeat": {
              "UserName": "augustoproiete",
              "UserDomainName": "XLSTACK"
            },
            "Computer": "Workstation"
          }
        }
      ]
    }
    

    在 Serilog 的 wiki 中,您可以找到由更广泛的 Serilog 社区开发和支持的接收器列表: https://github.com/serilog/serilog/wiki/Provided-Sinks

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-14
      • 2013-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多