CappedLog.loki 2.2.4

Extension for fixed size tagged log located in memory with Grafana Loki API

Install-Package CappedLog.loki -Version 2.2.4
dotnet add package CappedLog.loki --version 2.2.4
<PackageReference Include="CappedLog.loki" Version="2.2.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CappedLog.loki --version 2.2.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Scrape capped log to Grafana.Loki

Implementation of sending log messages to Grafana.Loki server

Example of usage

var services = new ServiceCollection();
services.AddLogging(configure => configure.AddCappedLog());

var cancel = new CancellationTokenSource();
var scrapeProcess = new CappedLog.LokiScrapeProcess(new Uri("http://localhost:3100/api/prom/push"), TimeSpan.FromSeconds(10));
var scrape = new CappedLog.CappedLogScrape();
int errorCnt = 0, successCnt = 0;
scrape
    .SetScrapeInterval(TimeSpan.FromSeconds(1))
    .SetScrape(CappedLogLoggerExtensions.DefaultCappedLog.Value, scrapeProcess);
scrape.OnError += e => ++errorCnt;
scrape.OnSuccess += s => ++successCnt;
var scrapeTask = scrape.Start(cancel.Token);
var serviceProvider = services.BuildServiceProvider();

var logger = serviceProvider.GetService<ILogger<TestScrapeLoki>>();
logger.LogError(new IndexOutOfRangeException("error message 1"), "Error {}", "1");
logger.LogCritical(new EventId(1, "Code 1"), new DllNotFoundException("error message 1"), "Critical {}", "2");
logger.LogWarning(new EventId(2), "Warning {}", "3");

Task.Delay(3000).Wait();
cancel.Cancel();

Assert.True(errorCnt == 0);
Assert.True(successCnt > 0);

Scrape capped log to Grafana.Loki

Implementation of sending log messages to Grafana.Loki server

Example of usage

var services = new ServiceCollection();
services.AddLogging(configure => configure.AddCappedLog());

var cancel = new CancellationTokenSource();
var scrapeProcess = new CappedLog.LokiScrapeProcess(new Uri("http://localhost:3100/api/prom/push"), TimeSpan.FromSeconds(10));
var scrape = new CappedLog.CappedLogScrape();
int errorCnt = 0, successCnt = 0;
scrape
    .SetScrapeInterval(TimeSpan.FromSeconds(1))
    .SetScrape(CappedLogLoggerExtensions.DefaultCappedLog.Value, scrapeProcess);
scrape.OnError += e => ++errorCnt;
scrape.OnSuccess += s => ++successCnt;
var scrapeTask = scrape.Start(cancel.Token);
var serviceProvider = services.BuildServiceProvider();

var logger = serviceProvider.GetService<ILogger<TestScrapeLoki>>();
logger.LogError(new IndexOutOfRangeException("error message 1"), "Error {}", "1");
logger.LogCritical(new EventId(1, "Code 1"), new DllNotFoundException("error message 1"), "Critical {}", "2");
logger.LogWarning(new EventId(2), "Warning {}", "3");

Task.Delay(3000).Wait();
cancel.Cancel();

Assert.True(errorCnt == 0);
Assert.True(successCnt > 0);

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CappedLog.loki:

Package Downloads
CappedLog.hosting.extensions
Extension for logging (CappedLog) and scraping (Grafana.Loki) data

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.2.4 131 10/9/2019