Skip to content

Commit

Permalink
Merge pull request #2 from IdentityStream/feature/bump
Browse files Browse the repository at this point in the history
Bump to latest dependencies
  • Loading branch information
ragnarstolsmark authored Mar 25, 2024
2 parents 645a3ab + 68148d2 commit f9c1a33
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
15 changes: 10 additions & 5 deletions Humio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogEvent> events) {
public async Task EmitBatchAsync(IEnumerable<LogEvent> events) {
try {
/*
* Example structured payload. See ingest structured data docs https://docs.humio.com/api/ingest-api/#structured-data
Expand All @@ -38,7 +38,7 @@ protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events) {
* [
{
"tags": {
"host": "server1",
"host": "server1",
"source": "application.log"
},
"events": [
Expand Down Expand Up @@ -84,5 +84,10 @@ protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events) {
Console.WriteLine($"Failed to ship logs to Humio: {e}");
}
}
}

public Task OnEmptyBatchAsync()
{
return Task.CompletedTask;
}
}
}
10 changes: 9 additions & 1 deletion HumioSinkExtensions.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
17 changes: 12 additions & 5 deletions Serilog.Sinks.Humio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@

<PropertyGroup>
<PackageId>Serilog.Sinks.Humio2</PackageId>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
<Authors>IdentityStream</Authors>
<Company>IdentityStream</Company>
<Description>A Serilog sink for logging to Humio.</Description>
<PackageTags>Serilog;sink;Humio</PackageTags>
<RepositoryUrl>https://github.com/IdentityStream-AS/Serilog.Sinks.Humio</RepositoryUrl>
<RepositoryUrl>https://github.com/IdentityStream/Serilog.Sinks.Humio</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>icon.png</PackageIcon>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="images\icon.png" Pack="true" PackagePath="\" />
<None Include="README.md" Pack="true" Visible="false" PackagePath="/" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="4.0.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
</ItemGroup>

</Project>

0 comments on commit f9c1a33

Please sign in to comment.