Skip to content

HTTP sink

FantasticFiasco edited this page Jan 26, 2021 · 15 revisions

The non-durable HTTP sink will send log events using HTTP POST over the network. A non-durable sink will lose data after a system or process restart.

Example

ILogger log = new LoggerConfiguration()
  .MinimumLevel.Verbose()
  .WriteTo.Http(requestUri: "https://www.mylogs.com")
  .CreateLogger();

log.Information("Logging {@Heartbeat} from {Computer}", heartbeat, computer);

Used in conjunction with Serilog.Settings.Configuration the same sink can be configured in the following way:

{
  "Serilog": {
    "MinimumLevel": "Verbose",
    "WriteTo": [
      {
        "Name": "Http",
        "Args": {
          "requestUri": "https://www.mylogs.com"
        }
      }
    ]
  }
}

Arguments

The following arguments are available when creating a HTTP sink.

  • requestUri - The URI the request is sent to.
  • batchPostingLimit - The maximum number of events to post in a single batch. Default value is 1000.
  • queueLimit - The maximum number of events stored in the queue in memory, waiting to be posted over the network. Default value is infinitely.
  • period - The time to wait between checking for event batches. Default value is 2 seconds.
  • textFormatter - The formatter rendering individual log events into text, for example JSON. Default value is NormalRenderedTextFormatter.
  • batchFormatter - The formatter batching multiple log events into a payload that can be sent over the network. Default value is DefaultBatchFormatter.
  • restrictedToMinimumLevel - The minimum level for events passed through the sink. Default value is LevelAlias.Minimum.
  • httpClient - A custom IHttpClient implementation. Default value is HttpClient.
  • configuration - Configuration passed to httpClient. Parameter is either manually specified when configuring the sink in source code or automatically passed in when configuring the sink using Serilog.Settings.Configuration.