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..0848182 100644 --- a/Serilog.Sinks.Humio.csproj +++ b/Serilog.Sinks.Humio.csproj @@ -6,24 +6,31 @@ 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 + true + true + true + snupkg + README.md + - - - + + + +