Loki.Client 1.0.14

dotnet add package Loki.Client --version 1.0.14                
NuGet\Install-Package Loki.Client -Version 1.0.14                
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="Loki.Client" Version="1.0.14" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Loki.Client --version 1.0.14                
#r "nuget: Loki.Client, 1.0.14"                
#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 Loki.Client as a Cake Addin
#addin nuget:?package=Loki.Client&version=1.0.14

// Install Loki.Client as a Cake Tool
#tool nuget:?package=Loki.Client&version=1.0.14                

lokiclient

介绍

c# loki SDK

软件架构

loki http sdk,support add、query、delete

安装教程

dotnet add package Loki.Client

使用说明

https://gitee.com/znyet/lokiclient

using Loki.Client

//client must be singleton mode(必须是单例模式)
var client = new LokiClient("http://localhost:3100");

var app = "qms";

await client.LogDebugAsync("debug", app);
await client.LogInfoAsync("info", app);
await client.LogWarningAsync("warning", app);
await client.LogErrorAsync("error", app);
await client.LogFatalAsync("fatal", app);
await client.LogCriticalAsync("LogCriticalAsync", app);

await client.LogDebugAsync(new { id = 1, name = "李四", age = 10, money = 112.2 }, app);
await client.LogErrorAsync(new Exception("这是个错误"), app);

//Test Single Insert
var entity = new LokiLogEntity
{
    LogLevel = LokiLogLevel.Info,
    App = app,
    Message = "Log单个信息",
    Time = DateTimeOffset.UtcNow
};
await client.LogAsync(entity);
//Test Bulk Insert
var app2 = "wms";
List<LokiLogEntity> list = [
    new LokiLogEntity
    {
        LogLevel = LokiLogLevel.Debug,
        App = app,
        Message = "Debug",
        Time = DateTimeOffset.UtcNow
    },
    new LokiLogEntity
    {
        LogLevel = LokiLogLevel.Debug,
        App = app,
        Message = "Debug2"
    },
    new LokiLogEntity
    {
        LogLevel = LokiLogLevel.Critical,
        App = app,
        Message = new{ id=1,name="Critical你好",address ="福建",money = 11.99}
    },
    new LokiLogEntity
    {
        LogLevel = LokiLogLevel.Info,
        App = app,
        Message = "Info"
    },
    new LokiLogEntity
    {
        LogLevel = LokiLogLevel.Warning,
        App = app,
        Message = "Warning"
    },
    new LokiLogEntity
    {
        LogLevel = LokiLogLevel.Error,
        App = app2,
        Message = "Error"
    },
    new LokiLogEntity
    {
        LogLevel = LokiLogLevel.Fatal,
        App = app2,
        Message = "Fatal"
    },
    new LokiLogEntity
    {
        LogLevel = LokiLogLevel.Info,
        App = app2,
        Message = new{ id=1,name="你好",address ="厦门",money = 11.99}
    }
];
await client.LogAsync(list);
//LokiQueue must be singleton mode(必须是单例模式)
var queue = new LokiQueue(client);

_ = Task.Run(async () =>
{
    while (true)
    {
        queue.AddLog(new LokiLogEntity
        {
            LogLevel = LokiLogLevel.Debug,
            App = app,
            Message = "Debug" + DateTime.Now.Microsecond,
            Time = DateTimeOffset.UtcNow
        });

        await Task.Delay(100);
    }
});
//LokiStream
//app、level (must required)

var stream = new LokiStream();
stream.AddLabel("app", "qms");
stream.AddLabel("level", "warning"); //debug、info、warning、error、fatal、critical、unknown
stream.AddLabel("host", "192.168.137.28");
stream.AddLabel("port", "80");

stream.AddValue(DateTimeOffset.UtcNow, "这是个测试==>" + stream.stream["level"]);
stream.AddValue(DateTimeOffset.UtcNow, new { a = 1, b = 2, c = 102.88, name = "你好,这是什么==>" + stream.stream["level"] });

//insert
await client.InsertAsync(stream);


var stream2 = new LokiStream();
stream2.AddLabel("app", "qms");
stream2.AddLabel("level", "error");
stream2.AddLabel("host", "192.168.137.30");
stream2.AddLabel("port", "6379");

stream2.AddValue(DateTimeOffset.UtcNow, "这是个测试stream2==>" + stream2.stream["level"]);
stream2.AddValue(DateTimeOffset.UtcNow, new { a = 1, b = 2, c = 3000, name = "你好,测试stream2==>" + stream2.stream["level"] });

try
{
    throw new AccessViolationException("Access denied");
}
catch (Exception ex)
{
    stream2.AddValue(DateTimeOffset.UtcNow, ex);
}

//insert list
await client.InsertAsync([stream, stream2]);
Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.14 99 12/1/2024