-
-
Notifications
You must be signed in to change notification settings - Fork 45
HTTP sink
The non-durable HTTP sink will send log events using HTTP POST over the network. The log events are stored in memory in the case that the log server cannot be reached.
The maximum number of log events stored in memory is configurable, and given that we reach this limit the sink will drop new log events in favour of keeping the old.
A non-durable sink will lose data after a system or process restart.
ILogger log = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Http(requestUri: "https://www.mylogs.com", queueLimitBytes: null)
.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",
"queueLimitBytes": null
}
}
]
}
}
The following arguments are available when creating a HTTP sink.
-
requestUri
- The URI the request is sent to. -
queueLimitBytes
- The maximum size, in bytes, of events stored in memory, waiting to be sent over the network. Specifynull
for no limit. -
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. -
flushOnClose
- Whether to send the log events stored in memory during the sink's disposal, thus ensuring that all generated log event are sent to the log server before sink closes. Default value istrue
. -
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. Ignored whenlevelSwitch
is specified. Default value isLevelAlias.Minimum
. -
levelSwitch
- A switch allowing the pass-through minimum level to be changed at runtime. -
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.