-
Notifications
You must be signed in to change notification settings - Fork 40
Application settings
Mykhailo Shevchuk edited this page Jun 6, 2026
·
17 revisions
The sink integrates with Serilog.Settings.Configuration, so it can be configured from appsettings.json (or any other Microsoft.Extensions.Configuration provider) instead of in code. Because JSON has a limited type system, a few parameters are expressed differently than their CLR types - those are called out in the table below.
| Parameter | CLR type | JSON type | Default | Notes |
|---|---|---|---|---|
uri |
string |
string | - (required) | Absolute http/https URI; validated at startup |
labels |
LokiLabel[] |
array of objects | [] |
Each object is { "key": "...", "value": "..." }
|
propertiesAsLabels |
string[] |
array of strings | [] |
Property names promoted to stream labels |
propertiesAsStructuredMetadata |
string[] |
array of strings | [] |
Property names attached as per-line structured metadata - see Structured metadata |
handleLogLevelAsLabel |
bool |
boolean | true |
Adds the level label - see Visualizing log level in Grafana
|
credentials |
LokiCredentials |
object | null |
Basic-auth credentials, e.g. { "login": "...", "password": "..." }
|
tenant |
string |
string | null |
Sets the X-Scope-OrgID header; validated at startup - see Authentication and multi-tenancy
|
traceIdMode |
LokiFieldDestination |
string | None |
None / Body / StructuredMetadata - see Trace and span enrichment
|
spanIdMode |
LokiFieldDestination |
string | None |
None / Body / StructuredMetadata - see Trace and span enrichment
|
batchSizeLimit |
int |
integer | 1000 |
Max events per HTTP POST |
queueLimit |
int |
integer | 50000 |
Bounded in-memory queue; newest events dropped when full |
period |
TimeSpan? |
string | 1 s |
Flush interval; JSON value is an "hh:mm:ss" string (see notes) |
eagerlyEmitFirstEvent |
bool |
boolean | true |
Flush immediately on the first event |
retryTimeLimit |
TimeSpan? |
string | 10 min |
Stop retrying a failed batch after this; JSON value is an "hh:mm:ss" string (see notes) |
restrictedToMinimumLevel |
LogEventLevel |
string | Verbose |
e.g. "Information" (see Enum.Parse) |
textFormatter |
ITextFormatter |
string | LokiJsonTextFormatter |
Type name "My.Namespace.MyType, MyAssembly" (see notes) |
exceptionFormatter |
ILokiExceptionFormatter |
string | LokiExceptionFormatter |
Type name "My.Namespace.MyType, MyAssembly" (see Custom exception formatting) |
httpClient |
HttpClient |
- | null |
Code-only; not configurable from JSON |
httpMessageHandler |
HttpMessageHandler |
- | null |
Code-only; not configurable from JSON |
-
period/retryTimeLimitareTimeSpan?in code (e.g.period: TimeSpan.FromSeconds(5)); in JSON they are written as"hh:mm:ss"strings (e.g."00:00:05"), which the settings binder converts toTimeSpan. Omit them to use the defaults. -
textFormatter/exceptionFormatterare bound by assembly-qualified type name and require a public parameterless constructor (LokiJsonTextFormatterandLokiExceptionFormatterboth have one). -
httpClient/httpMessageHandlerare runtime objects and can only be supplied in code (for example viaIHttpClientFactory). See Custom HttpClient.
{
"Serilog": {
"Using": [
"Serilog.Sinks.Grafana.Loki"
],
"MinimumLevel": {
"Default": "Debug"
},
"WriteTo": [
{
"Name": "GrafanaLoki",
"Args": {
"uri": "http://localhost:3100",
"labels": [
{
"key": "app",
"value": "web_app"
}
],
"propertiesAsLabels": [
"app"
],
"tenant": "my-tenant",
"propertiesAsStructuredMetadata": [ "RequestId" ],
"traceIdMode": "StructuredMetadata",
"batchSizeLimit": 500,
"period": "00:00:02"
}
}
]
}
}Several argument names changed in v9 (for example batchPostingLimit → batchSizeLimit), and a few were removed. See Upgrading from v8 to v9.