-
-
Notifications
You must be signed in to change notification settings - Fork 43
Durable file size rolled HTTP sink
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 file size specified in bufferFileSizeLimitBytes
, i.e. a new buffer file is created when the current buffer file has reached its limit. The maximum number of retained files is defined by retainedBufferFileCountLimit
, and when that limit is reached the oldest file is dropped to make room for a new.
A durable sink will protect you against data loss after a system or process restart.
ILogger log = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.DurableHttpUsingFileSizeRolledBuffers(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": "DurableHttpUsingFileSizeRolledBuffers",
"Args": {
"requestUri": "https://www.mylogs.com"
}
}
]
}
}
The following arguments are available when creating a durable HTTP sink using file size 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 patternbufferBaseFileName-*.txt
, which should not clash with any other file names in the same directory. Default value isBuffer
. -
bufferFileSizeLimitBytes
- The approximate maximum size, in bytes, to which a buffer file will be allowed to grow. For unrestricted growth, pass null. The default is 1 GB. To avoid writing partial events, the last event within the limit will be written in full even if it exceeds the limit. -
bufferFileShared
- Allow the buffer file to be shared by multiple processes. Default value isfalse
. -
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 byretainedBufferFileCountLimit
will be kept on the file system. For unlimited retention, passnull
. Default value is31
. -
logEventLimitBytes
- The maximum size, in bytes, for a serialized representation of a log event. Log events exceeding this size will be dropped. Specifynull
for no limit. Default value isnull
. -
logEventsInBatchLimit
- The maximum number of log events sent as a single batch over the network. Default value is1000
. -
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 isNormalRenderedTextFormatter
. -
batchFormatter
- The formatter batching multiple log events into a payload that can be sent over the network. Default value isArrayBatchFormatter
. -
restrictedToMinimumLevel
- The minimum level for events passed through the sink. Default value isLevelAlias.Minimum
. -
httpClient
- A customIHttpClient
implementation. Default value isJsonHttpClient
. -
configuration
- Configuration passed tohttpClient
. Parameter is either manually specified when configuring the sink in source code or automatically passed in when configuring the sink using Serilog.Settings.Configuration.