NLog.Targets.Loki
1.4.2
See the version list below for details.
dotnet add package NLog.Targets.Loki --version 1.4.2
NuGet\Install-Package NLog.Targets.Loki -Version 1.4.2
<PackageReference Include="NLog.Targets.Loki" Version="1.4.2" />
paket add NLog.Targets.Loki --version 1.4.2
#r "nuget: NLog.Targets.Loki, 1.4.2"
// Install NLog.Targets.Loki as a Cake Addin #addin nuget:?package=NLog.Targets.Loki&version=1.4.2 // Install NLog.Targets.Loki as a Cake Tool #tool nuget:?package=NLog.Targets.Loki&version=1.4.2
NLog Loki Target
This is an NLog target that sends messages to Loki using Loki's HTTP Push API. Available on .NET Standard 2.0 (.NET Core 2.0, .NET Framework 4.6.1 and above).
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.Targets.Loki
.NET Core CLI command:
dotnet add package NLog.Targets.Loki
Usage
Under .NET Core, remember to register NLog.Loki
as an extension assembly with 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">
<extensions>
<add assembly="NLog.Loki" />
</extensions>
<targets>
<target
name="loki"
xsi:type="loki"
batchSize="200"
taskDelayMilliseconds="500"
endpoint="http://localhost:3100"
username="myusername"
password="secret"
orderWrites="true"
compressionLevel="noCompression"
layout="${level}|${message}${onexception:|${exception:format=type,message,method:maxInnerExceptionLevel=5:innerFormat=shortType,message,method}}|source=${logger}">
<label name="app" layout="my-app-name" />
<label name="server" layout="${hostname:lowercase=true}" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="loki" />
</rules>
</nlog>
endpoint
must 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.
username
and password
are optional fields, used for basic authentication with Loki.
orderWrites
- Orders the logs by timestamp before sending them to loki when logs are batched in a single HTTP call. This is required if you use Loki v2.3 or below. But it is not required if you use Loki v2.4 or above (see out-of-order writes). You are strongly advised to set this value to false
when using Loki v2.4+ since it reduces allocations by about 20% by the serializer (default true
).
compressionLevel
- Gzip compression level applied if any when sending messages to Loki (default noCompression
). Possible values:
noCompression
: no compression applied, HTTP header will not specify a Content-Encoding with gzip value.fastest
: the compression operation should complete as quickly as possible, even if the resulting file is not optimally compressed.optimal
: the compression operation should be optimally compressed, even if the operation takes a longer time to complete.smallestSize
: supported by .NET 6 or greater only. The compression operation should create output as small as possible, even if the operation takes a longer time to complete.
label
elements can be used to enrich messages with additional labels. label/@layout
support usual NLog layout renderers.
Async Target
NLog.Loki
is an async target. You should not wrap it in an AsyncWrapper target. The following configuration options are supported. Make sure to adjust them to the expected throughput and criticality of your application's logs, especially the batch size, retry count and task delay.
taskTimeoutSeconds
- How many seconds a Task is allowed to run before it is cancelled (default 150 secs).
retryDelayMilliseconds
- How many milliseconds to wait before next retry (default 500ms, and will be doubled on each retry).
retryCount
- How many attempts to retry the same Task, before it is aborted (default 0, meaning no retry).
batchSize
- Gets or sets the number of log events that should be processed in a batch by the lazy writer thread (default 1).
taskDelayMilliseconds
- How many milliseconds to delay the actual write operation to optimize for batching (default 1 ms).
queueLimit
- Gets or sets the limit on the number of requests in the lazy writer thread request queue (default 10000).
overflowAction
- Gets or sets the action to be taken when the lazy writer thread request queue count exceeds the set limit (default Discard).
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- NLog (>= 4.7.15)
- System.Net.Http.Json (>= 6.0.0)
-
net6.0
- NLog (>= 4.7.15)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on NLog.Targets.Loki:
Package | Downloads |
---|---|
RavenDB.Cloud.Api.Client
This client library enables working with RavenDB Cloud API. For reference see: - RavenDB Cloud : https://cloud.ravendb.net - RavenDB Cloud Swagger UI : https://api.cloud.ravendb.net/swagger/index.html - RavenDB Cloud Swagger JSON : https://api.cloud.ravendb.net/api/v1/swagger.json |
|
Snow.Gqz.Shared.WebApi
1、修复CPU占用率过高问题,_waitMillisecond 由3 调整为 1000。 2、caching模块代码优化调整 |
|
Adnc.Shared.WebApi
该层实现了认证、鉴权、异常捕获、服务组件注册等公共类和中间件。所有微服务WebApi层的共享层,并且都需要依赖该层。 |
|
JRY.Library.Base
Package Description |
|
JRY.Library
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on NLog.Targets.Loki:
Repository | Stars |
---|---|
AlphaYu/adnc
.NET微服务/分布式开发框架,同时也适用于单体架构系统的开发。
|
Version | Downloads | Last updated |
---|---|---|
2.2.0 | 61,788 | 4/25/2024 |
2.1.2 | 16,754 | 3/9/2024 |
2.1.1 | 70,470 | 8/25/2023 |
2.1.0 | 4,899 | 8/10/2023 |
2.0.0 | 3,534 | 7/30/2023 |
1.5.1 | 26,605 | 7/30/2023 |
1.5.0 | 18,831 | 7/30/2023 |
1.4.6 | 124,432 | 11/27/2022 |
1.4.5 | 27,272 | 10/22/2022 |
1.4.4 | 100,636 | 6/11/2022 |
1.4.3 | 55,307 | 5/26/2022 |
1.4.2 | 1,684 | 5/23/2022 |
1.4.1 | 12,195 | 3/27/2022 |
1.4.0 | 3,036 | 3/13/2022 |
1.3.2 | 1,025 | 3/12/2022 |
1.3.1 | 5,545 | 2/19/2022 |
1.3.0 | 6,299 | 1/24/2022 |
1.2.1 | 5,005 | 1/19/2022 |
1.2.1-preview2 | 723 | 1/19/2022 |
1.2.1-preview1 | 754 | 1/19/2022 |