Skip to content

anton-gogolev/nlog.loki

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NLog Loki Target

CI

This is an NLog target that sends messages to Loki.

Loki is a horizontally-scalable, highly-available, multi-tenant log aggregation system inspired by Prometheus. It is designed to be very cost effective and easy to operate.

Installation

The NLog.Loki NuGet package can be found here. You can install it via one of the following commands below:

NuGet command:

Install-Package NLog.Loki

.NET Core CLI command:

dotnet add package NLog.Loki

Usage

Under .NET Core, remember to register NLog.Loki as an extension assembly with NLog:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <extensions>
    <add assembly="NLog.Loki" />
  </extensions>

</nlog>

You can now add a Loki target to your configuration file:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <target name="loki" xsi:type="loki" endpoint="${environment:LOKI_ENDPOINT_URI}">
    <label name="level" layout="${level:lowercase=true}" />
    <label name="server" layout="${hostname:lowercase=true}" />
  </target>

  <rules>
    <logger name="*" minlevel="Info" writeTo="loki" />
  </rules>

</nlog>

The @endpoint attribute is a Layout that must ultimately resolve to a fully-qualified absolute URL of the Loki Server when running in a Single Proccess Mode or of the Loki Distributor when running in Microservices Mode. When an invalid URI is encountered, all log messages are silently discarded.

label elements can be used to enrich messages with additional labels. label/@layout support usual NLog layout renderers.

About

NLog Loki Target

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages