dotnet-cloudlog
is a client library for Anexia CloudLog. It provides a simple API for sending events to a CloudLog
index directly from your .NET application.
Note: Usually it is considered best-practice to write rotating log-files to the filesystem, and send those logs to
CloudLog via Filebeat
.
With a correctly set up .NET SDK, run in PowerShell
:
Install-Package Anexia.BDP.CloudLog
To send unstructured messages to the CloudLog index, use the code as follows:
using System.Net.Http;
using Anexia.BDP.CloudLog;
…
var client = new Client("SomeIndex", "SomeToken");
var message = "Some message that you want to send to the CloudLog index";
client.PushEvent(message);
…
To send structured messages to the CloudLog index, use the code as follows:
using System.Net.Http;
using Anexia.BDP.CloudLog;
…
var client = new Client("SomeIndex", "SomeToken");
var message = "{\"message\":\"Something\",\"timestamp\":\"1669816693\"}"; // `timestamp` is a UNIX timestamp
client.PushEvent(message);
…
HttpClient
may be passed to the constructor to allow for modification of the HTTP requests, as shown in the code
as follows:
using System.Net.Http;
using Anexia.BDP.CloudLog;
…
var client1 = new Client("SomeIndex", "SomeToken", new HttpClient());
var client2 = new Client("SomeIndex", "SomeToken", HttpFactory.Create());
…
The methods PushEvent
and PushEvents
return an awaitable PostAsync
task, as shown in the code
as follows:
using System;
using System.Net.Http;
using Anexia.BDP.CloudLog;
…
var client = new Client("SomeIndex", "SomeToken");
var message = "Some message that you want to send to the CloudLog index";
var response = await client.PushEvent(message);
Console.WriteLine(response.StatusCode); // should print `201`
…
Supported | |
---|---|
.Net 5.0 | ✓ |
.Net 6.0 | ✓ |
.Net 7.0 | ✓ |