From c0f3a357bb7fb517f2731b49335ef085258ee82a Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Mar 2024 14:13:42 +0100 Subject: [PATCH 1/2] Bump to latest dependencies --- Humio.cs | 15 ++++++++++----- HumioSinkExtensions.cs | 10 +++++++++- Serilog.Sinks.Humio.csproj | 10 +++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Humio.cs b/Humio.cs index 9423307..1676922 100644 --- a/Humio.cs +++ b/Humio.cs @@ -13,20 +13,20 @@ using Serilog.Sinks.PeriodicBatching; namespace Serilog.Sinks.Humio { - public class Humio : PeriodicBatchingSink { + public class Humio : IBatchedLogEventSink { private readonly string _ingestToken; private readonly ITextFormatter _formatter; private static readonly HttpClient HttpClient = new HttpClient(); private readonly Uri _uri; - public Humio(string ingestToken, string url) : base(10, TimeSpan.FromSeconds(5)) { + public Humio(string ingestToken, string url) { _ingestToken = ingestToken; _formatter = new JsonFormatter(); _uri = new Uri( $"{url}/api/v1/ingest/humio-structured"); } - protected override async Task EmitBatchAsync(IEnumerable events) { + public async Task EmitBatchAsync(IEnumerable events) { try { /* * Example structured payload. See ingest structured data docs https://docs.humio.com/api/ingest-api/#structured-data @@ -38,7 +38,7 @@ protected override async Task EmitBatchAsync(IEnumerable events) { * [ { "tags": { - "host": "server1", + "host": "server1", "source": "application.log" }, "events": [ @@ -84,5 +84,10 @@ protected override async Task EmitBatchAsync(IEnumerable events) { Console.WriteLine($"Failed to ship logs to Humio: {e}"); } } - } + + public Task OnEmptyBatchAsync() + { + return Task.CompletedTask; + } + } } \ No newline at end of file diff --git a/HumioSinkExtensions.cs b/HumioSinkExtensions.cs index f76f089..5fb5d20 100644 --- a/HumioSinkExtensions.cs +++ b/HumioSinkExtensions.cs @@ -1,12 +1,20 @@ using Serilog.Configuration; using Serilog.Events; +using Serilog.Sinks.PeriodicBatching; +using System; namespace Serilog.Sinks.Humio { public static class HumioSinkExtensions { public static LoggerConfiguration Humio( this LoggerSinkConfiguration loggerConfiguration, string ingestToken = null, string url = "https://cloud.humio.com", LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum) { - return loggerConfiguration.Sink(new Humio(ingestToken, url), restrictedToMinimumLevel); + var batchingOptions = new PeriodicBatchingSinkOptions + { + Period = TimeSpan.FromSeconds(5), + BatchSizeLimit = 10, + }; + var sink = new PeriodicBatchingSink(new Humio(ingestToken, url), batchingOptions); + return loggerConfiguration.Sink(sink, restrictedToMinimumLevel); } } } \ No newline at end of file diff --git a/Serilog.Sinks.Humio.csproj b/Serilog.Sinks.Humio.csproj index 1e12dd5..d97cf26 100644 --- a/Serilog.Sinks.Humio.csproj +++ b/Serilog.Sinks.Humio.csproj @@ -6,12 +6,12 @@ Serilog.Sinks.Humio2 - 1.1.0 + 1.2.0 IdentityStream IdentityStream A Serilog sink for logging to Humio. Serilog;sink;Humio - https://github.com/IdentityStream-AS/Serilog.Sinks.Humio + https://github.com/IdentityStream/Serilog.Sinks.Humio MIT icon.png @@ -21,9 +21,9 @@ - - - + + + From 68148d279270efbcbe93d76245881e68e2855862 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Mar 2024 14:16:11 +0100 Subject: [PATCH 2/2] Add SourceLink, snupkg and README to package --- Serilog.Sinks.Humio.csproj | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Serilog.Sinks.Humio.csproj b/Serilog.Sinks.Humio.csproj index d97cf26..0848182 100644 --- a/Serilog.Sinks.Humio.csproj +++ b/Serilog.Sinks.Humio.csproj @@ -14,16 +14,23 @@ https://github.com/IdentityStream/Serilog.Sinks.Humio MIT icon.png + true + true + true + snupkg + README.md + +