Skip to content

Application settings

Mykhailo Shevchuk edited this page Jul 19, 2022 · 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
propertiesAsLabels IEnumerable<string> array of strings
credentials LokiCredentials object
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"
reservedPropertyRenamingStrategy IReservedPropertyRenamingStrategy string See Type.GetType "MyNamespace.MyClass, MyAssembly"
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
  • propertiesAsLabels - the list of properties, which should be mapped to Loki labels. The rest will be passed as a part of payload and could be used, using Loki's | json parser
  • credentials - credentials, which will be used for basic auth
  • 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 formater
  • httpClient - the customizable HttpClient
  • reservedPropertyRenamingStrategy - the strategy, used for property renaming in cases of collisions
  • useInternalTimestamp - should use internal sink timestamp instead of application one to use as log timestamp