serilog-sinks-cloudlog
is a Serilog sink that delivers log events to Anexia CloudLog.
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 Serilog.Sinks.CloudLog
To enable the sink, call WriteTo.CloudLog()
.
To create logger without passing a HttpClient
instance, use the code as follows:
using Serilog;
…
Log.Logger = new LoggerConfiguration()
.WriteTo.CloudLog(index: "index-name", token: "token")
.CreateLogger();
Log.Information("Hello CloudLog!");
To create logger with a custom HttpClient
instance, use the code as follows:
using Serilog;
…
Log.Logger = new LoggerConfiguration()
.WriteTo.CloudLog(
index: "index-name",
token: "token",
(nameOfClass)=>{
clientFactory.CreateClient(nameOfClass);
})
)
.CreateLogger();
Log.Information("Hello CloudLog!");
Note: HttpClient
has to be enabled: Make HTTP requests using IHttpClientFactory
To create logger with a custom HttpClient
instance using a IHttpClientFactory
, use the code as follows:
using Serilog;
…
Log.Logger = new LoggerConfiguration()
.WriteTo.CloudLog(
index: "index-name",
token: "token",
clientFactory
)
.CreateLogger();
Log.Information("Hello CloudLog!");
Note: HttpClient
has to be enabled: Make HTTP requests using IHttpClientFactory
Supported | |
---|---|
.Net 5.0 | ✓ |
.Net 6.0 | ✓ |
.Net 7.0 | ✓ |