Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post Serilog logs to Rest api

I want to write my .net core server'S logs to a Rest-api by using Serilogger. I've checked several ways, and tried Seq sink by giving my rest api's url. But it does not work effectively. Is there any rest api sink for that? Thanks for helping

"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"
              }
            }
          ]
        }
      }
    ],
like image 324
Mehmet Özcan Avatar asked Oct 14 '25 07:10

Mehmet Özcan


1 Answers

You can try Serilog.Sinks.Http, a Serilog sink for sending log events over HTTP.

Below is an example of a hypothetical JSON payload:

{
  "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"
      }
    }
  ]
}

In Serilog's wiki you can find a list of sinks developed and supported by the wider Serilog community: https://github.com/serilog/serilog/wiki/Provided-Sinks

like image 89
C. Augusto Proiete Avatar answered Oct 18 '25 00:10

C. Augusto Proiete



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!