-
Notifications
You must be signed in to change notification settings - Fork 41
Application settings
Mykhailo Shevchuk edited this page Jun 5, 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 |
handleLogLevelAsLabel |
bool |
boolean | true |
Adds the level label — see Visualizing log level in Grafana
|
credentialsLogin |
string |
string | null |
Basic-auth user; pair with credentialsPassword
|
credentialsPassword |
string |
string | null |
Basic-auth password |
tenant |
string |
string | null |
Sets the X-Scope-OrgID header — see Authentication and multi-tenancy
|
enrichTraceId |
bool |
boolean | false |
See Trace and span enrichment |
enrichSpanId |
bool |
boolean | false |
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 |
string |
string | "00:00:01" |
Flush interval, format hh:mm:ss (see notes) |
eagerlyEmitFirstEvent |
bool |
boolean | true |
Flush immediately on the first event |
retryTimeLimit |
string |
string | "00:10:00" |
Stop retrying a failed batch after this, format hh:mm:ss (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/retryTimeLimitare strings, notTimeSpan— formathh:mm:ss, e.g."00:00:05". This keeps a single call signature that binds cleanly from JSON. 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",
"enrichTraceId": true,
"batchSizeLimit": 500,
"period": "00:00:02"
}
}
]
}
}Several argument names changed in v9 (for example credentials → credentialsLogin/credentialsPassword, batchPostingLimit → batchSizeLimit), and a few were removed. See Upgrading from v8 to v9.