Serilog.Sinks.Grafana.Loki 8.1.0

.NET Standard 2.0
dotnet add package Serilog.Sinks.Grafana.Loki --version 8.1.0
NuGet\Install-Package Serilog.Sinks.Grafana.Loki -Version 8.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.Sinks.Grafana.Loki --version 8.1.0
#r "nuget: Serilog.Sinks.Grafana.Loki, 8.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Serilog.Sinks.Grafana.Loki as a Cake Addin
#addin nuget:?package=Serilog.Sinks.Grafana.Loki&version=8.1.0

// Install Serilog.Sinks.Grafana.Loki as a Cake Tool
#tool nuget:?package=Serilog.Sinks.Grafana.Loki&version=8.1.0


Made in Ukraine Build status NuGet version Latest release Documentation

Terms of use

By using this project or its source code, for any purpose and in any shape or form, you grant your implicit agreement to all the following statements:

  • You condemn Russia and its military aggression against Ukraine
  • You recognize that Russia is an occupant that unlawfully invaded a sovereign state
  • You support Ukraine's territorial integrity, including its claims over temporarily occupied territories of Crimea and Donbas
  • You reject false narratives perpetuated by Russian state propaganda

Glory to Ukraine! 🇺🇦

Table of contents

What is this sink and Loki?

The Serilog Grafana Loki sink project is a sink (basically a writer) for the Serilog logging framework. Structured log events are written to sinks and each sink is responsible for writing it to its own backend, database, store etc. This sink delivers the data to Grafana Loki, a horizontally-scalable, highly-available, multi-tenant log aggregation system. It allows you to use Grafana for visualizing your logs.

You can find more information about what Loki is over on Grafana's website here.


  • Formats and batches log entries to Loki via HTTP (using actual API)
  • Global and contextual labels support
  • Flexible Loki labels configuration possibilities
  • Collision avoiding mechanism for labels
  • Integration with Serilog.Settings.Configuration
  • Customizable HTTP clients
  • HTTP client with gzip compression
  • Using fast System.Text.Json library for serialization
  • Possibility of sending json logs to Loki
  • No dependencies on another sinks


Features comparison table could be found here

Breaking changes

The list of breaking changes could be found here


The Serilog.Sinks.Grafana.Loki NuGet package could be found here. Alternatively you can install it via one of the following commands below:

NuGet command:

Install-Package Serilog.Sinks.Grafana.Loki

.NET Core CLI:

dotnet add package Serilog.Sinks.Grafana.Loki

In the following example, the sink will send log events to Loki available on http://localhost:3100

ILogger logger = new LoggerConfiguration()

logger.Information("The god of the day is {@God}", odin)

Used in conjunction with Serilog.Settings.Configuration the same sink can be configured in the following way:

  "Serilog": {
    "Using": [
    "MinimumLevel": {
      "Default": "Debug"
    "WriteTo": [
        "Name": "GrafanaLoki",
        "Args": {
          "uri": "http://localhost:3100",
          "labels": [
              "key": "app",
              "value": "web_app"
          "propertiesAsLabels": [

Description of parameters and configuration details could be found here.

Custom HTTP Client

Serilog.Loki.Grafana.Loki exposes ILokiHttpClient interface with the main operations, required for sending logs. In order to use a custom HttpClient you can extend of default implementations:

  • Serilog.Sinks.Grafana.Loki.HttpClients.BaseLokiHttpClient (implements creation of internal HttpClient and setting credentials)
  • Serilog.Sinks.Grafana.Loki.HttpClients.LokiHttpClient (default client which sends logs via HTTP)
  • Serilog.Sinks.Grafana.Loki.HttpClients.LokiGzipHttpClient (default client which sends logs via HTTP with gzip compression)

or create one implementing Serilog.Sinks.Grafana.Loki.ILokiHttpClient.

// CustomHttpClient.cs

public class CustomHttpClient : BaseLokiHttpClient
    public override Task<HttpResponseMessage> PostAsync(string requestUri, Stream contentStream)
        return base.PostAsync(requestUri, contentStream);
// Usage

Log.Logger = new LoggerConfiguration()
         httpClient: new CustomHttpClient()

Sending json content to Loki

From v8 Serilog.Sinks.Grafana.Loki uses LokiJsonTextFormatter by default, which allows to send logs to Loki as a JSON-payloads. This allows easier filtering in Loki v2, more information about how to filter can be found here

Also, you could implement your own formatter, implementing Serilog.Formatting.ITextFormatter interface and pass it to the sink configuration.

Example configuration:

  "Serilog": {
    "Using": [
    "MinimumLevel": {
      "Default": "Debug"
    "WriteTo": [
        "Name": "GrafanaLoki",
        "Args": {
          "uri": "http://localhost:3100",
          "textFormatter": "My.Awesome.Namespace.MyTextFormatter, MyCoolAssembly"

Inspiration and Credits

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (15)

Showing the top 5 NuGet packages that depend on Serilog.Sinks.Grafana.Loki:

Package Downloads



Only.CoffeeFace web api stuff




Package Description



GitHub repositories (6)

Showing the top 5 popular GitHub repositories that depend on Serilog.Sinks.Grafana.Loki:

Repository Stars
A simple recipe for .NET Core microservices.
Sample Event Sourcing implementation with .NET Core
This project aims to create an easy to use, extendable and customizable server for a MMORPG called "MU Online".
A modern client-server application for the Soulseek file sharing network.
Convert workout data from Peloton into JSON/TCX/FIT files and automatically upload to Garmin Connect
Version Downloads Last updated
8.1.0 120,826 11/26/2022
8.0.1 77,855 10/13/2022
8.0.0 189,879 7/19/2022
8.0.0-beta.0 6,314 4/1/2022
7.1.1 419,335 3/23/2022
7.1.0 546,935 9/21/2021
7.0.2 30,991 8/30/2021
7.0.1 10,788 8/17/2021
7.0.0 399 8/15/2021
6.0.1 66,062 6/7/2021
6.0.0 12,100 6/2/2021
5.1.3 26,130 5/10/2021
5.1.2 40,276 4/13/2021
5.0.0 120,813 11/29/2020
4.0.2 3,622 11/15/2020
4.0.1 357 11/14/2020
4.0.0 957 11/8/2020
3.1.0 6,667 5/19/2020
3.0.1 853 5/18/2020
3.0.0 848 5/17/2020

For release notes, please see the change log on GitHub.