Skip to content

Durable time rolled HTTP sink

FantasticFiasco edited this page Apr 12, 2022 · 12 revisions

The durable HTTP sink will send log events using HTTP POST over the network. The log events are initially stored on disk to prevent data loss, and then periodically sent over the network to the log server.

The buffer files will use a rolling behavior defined by the time interval specified in bufferRollingInterval, i.e. a new buffer file is created every time a new interval is started. The maximum size of a buffer file is defined by bufferFileSizeLimitBytes, and when that limit is reached all new log events will be dropped until a new interval is started.

A durable sink will protect you against data loss after a system or process restart.

Example

ILogger log = new LoggerConfiguration()
  .MinimumLevel.Verbose()
  .WriteTo.DurableHttpUsingTimeRolledBuffers(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": "DurableHttpUsingTimeRolledBuffers",
        "Args": {
          "requestUri": "https://www.mylogs.com"
        }
      }
    ]
  }
}

Arguments

The following arguments are available when creating a durable HTTP sink using time rolled buffers.

  • requestUri - The URI the request is sent to.

  • bufferBaseFileName - The relative or absolute path for a set of files that will be used to buffer events until they can be successfully transmitted across the network. Individual files will be created using the pattern bufferBaseFileName-*.txt, which should not clash with any other file names in the same directory. Default value is Buffer.

  • bufferRollingInterval - The interval at which the buffer files are rotated. Default value is Day.

  • bufferFileSizeLimitBytes - The approximate maximum size, in bytes, to which a buffer file for a specific time interval will be allowed to grow. By default no limit will be applied.

  • bufferFileShared - Allow the buffer file to be shared by multiple processes. Default value is false.

  • retainedBufferFileCountLimit - The maximum number of buffer files that will be retained, including the current buffer file. Under normal operation only 2 files will be kept, however if the log server is unreachable, the number of files specified by retainedBufferFileCountLimit will be kept on the file system. For unlimited retention, pass null. Default value is 31.

  • logEventLimitBytes - The maximum size, in bytes, for a serialized representation of a log event. Log events exceeding this size will be dropped. Specify null for no limit. Default value is null.

  • logEventsInBatchLimit - The maximum number of log events sent as a single batch over the network. Default value is 1000.

  • batchSizeLimitBytes - The approximate maximum size, in bytes, for a single batch. The value is an approximation because only the size of the log events are considered. The extra characters added by the batch formatter, where the sequence of serialized log events are transformed into a payload, are not considered. Please make sure to accommodate for those.

    Another thing to mention is that although the sink does its best to optimize for this limit, if you decide to use an implementation of IHttpClient that is compressing the payload, e.g. JsonGzipHttpClient, this parameter describes the uncompressed size of the log events. The compressed size might be significantly smaller depending on the compression algorithm and the repetitiveness of the log events.

    Default value is null.

  • 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 ArrayBatchFormatter.

  • restrictedToMinimumLevel - The minimum level for events passed through the sink. Default value is LevelAlias.Minimum.

  • httpClient - A custom IHttpClient implementation. Default value is JsonHttpClient.

  • 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.