All Projects → serilog-contrib → serilog-sinks-grafana-loki

serilog-contrib / serilog-sinks-grafana-loki

Licence: MIT License
A Serilog sink sending log events to Grafana Loki

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to serilog-sinks-grafana-loki

loki exporter
Prometheus exporter to collect metrics and run queries against the Grafana Loki API.
Stars: ✭ 28 (-49.09%)
Mutual labels:  grafana, loki
dns-collector
Aggregator, analyzer, transporter and logging for your DNS logs
Stars: ✭ 58 (+5.45%)
Mutual labels:  grafana, loki
Loki
Like Prometheus, but for logs.
Stars: ✭ 14,483 (+26232.73%)
Mutual labels:  grafana, loki
gimlet-stack
Bootstrap curated Kubernetes stacks. Logging, metrics, ingress and more - delivered with gitops.
Stars: ✭ 12 (-78.18%)
Mutual labels:  grafana, loki
VictoriaLogs
Loki On VictoriaMetrics
Stars: ✭ 58 (+5.45%)
Mutual labels:  grafana, loki
loki-multi-tenant-proxy
Grafana Loki multi-tenant Proxy. Needed to deploy Grafana Loki in a multi-tenant way
Stars: ✭ 48 (-12.73%)
Mutual labels:  grafana, loki
octane-exporter
Export Laravel Octane metrics using this Prometheus exporter.
Stars: ✭ 14 (-74.55%)
Mutual labels:  grafana
histou
Adds templates to Grafana in combination with nagflux
Stars: ✭ 33 (-40%)
Mutual labels:  grafana
darksky2influxdb
Stores wheather forcecast data from darkskyapi into a influxdb database
Stars: ✭ 21 (-61.82%)
Mutual labels:  grafana
arcus.observability
Observability with Microsoft Azure in a breeze.
Stars: ✭ 24 (-56.36%)
Mutual labels:  serilog
pcap-processor
Read and process pcap files using this nifty tool
Stars: ✭ 36 (-34.55%)
Mutual labels:  sink
cdn-up-and-running
CDN Up and Running - an introduction about how modern CDNs works
Stars: ✭ 131 (+138.18%)
Mutual labels:  grafana
ASPNETcoreAngularJWT
Angular in ASP.NET Core with JWT solution by systemjs
Stars: ✭ 48 (-12.73%)
Mutual labels:  serilog
grafana-ng
Grafana on .net core + angular.
Stars: ✭ 51 (-7.27%)
Mutual labels:  grafana
webperf-dashboard
Web Performance Dashboard forked from https://github.com/boyney123/garie
Stars: ✭ 51 (-7.27%)
Mutual labels:  grafana
serilog-sinks-xamarin
A Serilog sink that writes events to Xamarin mobile targets
Stars: ✭ 46 (-16.36%)
Mutual labels:  serilog
whatsapp-tracking
Scraping the status of WhatsApp contacts
Stars: ✭ 49 (-10.91%)
Mutual labels:  grafana
zabbix-monitor
monitor system based on zabbix API pyzaabix grafana
Stars: ✭ 70 (+27.27%)
Mutual labels:  grafana
microservices-observability
🎉 Microservices Observability - Log Aggregation, Distributed Tracking, Metrics
Stars: ✭ 40 (-27.27%)
Mutual labels:  grafana
grafana-api-java-client
A simple java client for interacting with Grafana using a fluent interface.
Stars: ✭ 40 (-27.27%)
Mutual labels:  grafana

Serilog.Sinks.Grafana.Loki

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.

Features:

  • Formats and batches log entries to Loki via HTTP (using actual API)
  • Global and contextual labels support
  • Labels filtration modes
  • 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

Comparison

Features comparison table could be found here

Breaking changes

The list of breaking changes could be found here

Quickstart

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()
    .WriteTo.GrafanaLoki(
        "http://localhost:3100")
    .CreateLogger();

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": [
      "Serilog.Sinks.Grafana.Loki"
    ],
    "MinimumLevel": {
      "Default": "Debug"
    },
    "WriteTo": [
      {
        "Name": "GrafanaLoki",
        "Args": {
          "uri": "http://localhost:3100",
          "labels": [
            {
              "key": "app",
              "value": "web_app"
            }
          ],
          "outputTemplate": "{Timestamp:dd-MM-yyyy HH:mm:ss} [{Level:u3}] [{ThreadId}] {Message}{NewLine}{Exception}"
        }
      }
    ]
  }
}

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()
    .WriteTo.GrafanaLoki(
         "http://localhost:3100",
         httpClient: new CustomHttpClient()
    )
    .CreateLogger();

Sending json content to Loki

Serilog.Sinks.Grafana.Loki can be configured to send json content to Loki, this enables easier filtering in Loki v2, more information about how to filter can be found here
Example configuration:

{
  "Serilog": {
    "Using": [
      "Serilog.Sinks.Grafana.Loki"
    ],
    "MinimumLevel": {
      "Default": "Debug"
    },
    "WriteTo": [
      {
        "Name": "GrafanaLoki",
        "Args": {
          "uri": "http://localhost:3100",
          "textFormatter": "Serilog.Sinks.Grafana.Loki.LokiJsonTextFormatter, Serilog.Sinks.Grafana.Loki"
        }
      }
    ]
  }
}

Inspiration and Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].