Skip to content

Application settings

Mykhailo Shevchuk edited this page Nov 6, 2021 · 11 revisions

The process of releasing software often starts with deployment to a staging environment, and after quality is assured the software is promoted to production. To minimize the risk of introducing new bugs one would like to promote the same binary, but with changes to the configuration. This means that configuration cannot be defined at compile-time, it must be applied at run-time. This is where the story of application settings begin.

The initiative from Microsoft to introduce Microsoft.Extensions.Configuration meant that other libraries, like Serilog, had a solid foundation to build their own configuration upon. This sink, in combination with Serilog.Settings.Configuration, supports application configuration by using Microsoft.Extensions.Configuration.Json or any other provider. The limited type system in JSON however forces us to write some of the configuration parameters in a slightly different way. The following chapters will list all configurable parameters and highlights those that in JSON have a different format than those defined in code.

Grafana Loki sink

Parameter name CLR type JSON type JSON remarks JSON example
uri string string
labels IEnumerable<LokiLabel> array of objects
filtrationMode LokiLabelFiltrationMode string See Enum.Parse "Include"
filtrationLabels IEnumerable<string> array of strings Should not be empty array
credentials LokiCredentials object
outputTemplate string string
restrictedToMinimumLevel LogEventLevel string See Enum.Parse "Verbose"
batchPostingLimit int integer
queueLimit int integer
period TimeSpan string See TimeSpan.Parse "00:00:02"
textFormatter ITextFormatter string See Type.GetType "MyNamespace.MyClass, MyAssembly"
httpClient ILokiHttpClient string See Type.GetType "MyNamespace.MyClass, MyAssembly"
createLevelLabel bool boolean
useInternalTimestamp bool boolean

Parameters description

  • uri - the root URI of Loki
  • labels - the global log event labels, which will be user for enriching all requests
  • filtrationMode - the mode for labels filtration (Include/Exclude)
  • filtrationLabels - the list of label keys used for filtration
  • credentials - credentials, which will be used for basic auth
  • outputTemplate - a message template describing the format used to write to the sink. Default value is [{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}
  • restrictedToMinimumLevel - the minimum level for events passed through the sink
  • batchPostingLimit - the maximum number of events to post in a single batch. Default value is 1000
  • queueLimit - the maximum number of events stored in the queue in memory, waiting to be posted over the network. Default value is infinitely
  • 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
  • httpClient - the customizable HttpClient
  • createLevelLabel - should level label be created. Default value is false. The level label always won't be created while using ILabelAwareTextFormatter
  • useInternalTimestamp - should use internal sink timestamp instead of application one to use as log timestamp
Clone this wiki locally