Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotnet 8.0 updates #171

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY . /
FROM microsoft/dotnet:8.0-sdk AS build
ADD . /
WORKDIR /sample/Sample
RUN dotnet restore
RUN dotnet publish -c Release -o out -f net6.0
RUN dotnet publish -c Release -o out -f net8.0

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS runtime
FROM microsoft/dotnet:8.0-runtime AS runtime
WORKDIR /sample/Sample
COPY --from=build /sample/Sample/out ./
ENTRYPOINT ["dotnet", "Sample.dll"]
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '{build}'
skip_tags: true
image:
- Visual Studio 2019
- Visual Studio 2022
- Ubuntu2004
configuration:
- Release
Expand Down
5 changes: 2 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ dotnet restore
for path in src/**/Serilog.Sinks.Splunk.csproj; do
dotnet build -f netstandard2.0 -c Release ${path}
dotnet build -f netstandard2.1 -c Release ${path}
dotnet build -f net6.0 -c Release ${path}
done

for path in test/*.Tests/*.csproj; do
dotnet test -f net6.0 -c Release ${path}
dotnet test -f net8.0 -c Release ${path}
done

dotnet build -f net6.0 -c Release sample/Sample/Sample.csproj
dotnet build -f net8.0 -c Release sample/Sample/Sample.csproj
11 changes: 5 additions & 6 deletions sample/Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.Extensions.Configuration;
using Serilog;
using Serilog.Sinks.Splunk;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Sample
{
Expand All @@ -18,7 +18,7 @@ public class Program
public static void Main(string[] args)
{
// Bootstrap a simple logger.
var logger = new LoggerConfiguration()
var logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();

Expand Down Expand Up @@ -94,7 +94,6 @@ public static void UsingAppSettingsJson(int eventsToCreate)
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddUserSecrets<Program>()
.Build();

Log.Logger = new LoggerConfiguration()
Expand Down
6 changes: 3 additions & 3 deletions sample/Sample/Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>The Splunk Sink for Serilog</Description>
<VersionPrefix>4.0.0</VersionPrefix>
<Authors>Matthew Erbs, Serilog Contributors</Authors>
<TargetFrameworks>netstandard2.1;netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net6.0;net8.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Serilog.Sinks.Splunk</AssemblyName>
<PackageId>Serilog.Sinks.Splunk</PackageId>
Expand All @@ -24,7 +24,7 @@

<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="4.0.1" />
</ItemGroup>

</Project>
7 changes: 5 additions & 2 deletions src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ public EventCollectorSink(
: new EventCollectorClient(eventCollectorToken);
}

/// <inheritdoc />
public async Task EmitBatchAsync(IEnumerable<LogEvent> events)
/// <summary>
/// Emit a batch of log events, running asynchronously.
/// </summary>
/// <param name="events">The events to emit.</param>
public virtual async Task EmitBatchAsync(IEnumerable<LogEvent> events)
{
var allEvents = new StringWriter();

Expand Down
93 changes: 51 additions & 42 deletions src/Serilog.Sinks.Splunk/SplunkLoggingConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
// limitations under the License.


using System;
using System.Net.Http;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting;
using Serilog.Formatting.Json;
using Serilog.Sinks.PeriodicBatching;
using Serilog.Sinks.Splunk;
using System;
using System.Net.Http;

namespace Serilog
{
Expand Down Expand Up @@ -64,25 +65,33 @@ public static LoggerConfiguration EventCollector(
int batchIntervalInSeconds = 2,
int batchSizeLimit = 100,
int? queueLimit = null,
HttpMessageHandler messageHandler = null,
HttpMessageHandler messageHandler = null,
LoggingLevelSwitch levelSwitch = null)
{
if (configuration == null) throw new ArgumentNullException(nameof(configuration));

var batchingOptions = new PeriodicBatchingSinkOptions
{
BatchSizeLimit = batchSizeLimit,
Period = TimeSpan.FromSeconds(batchIntervalInSeconds),
EagerlyEmitFirstEvent = true,
QueueLimit = queueLimit
};

var eventCollectorSink = new EventCollectorSink(
splunkHost,
eventCollectorToken,
eventCollectorToken,
uriPath,
source,
sourceType,
host,
source,
sourceType,
host,
index,
formatProvider,
renderTemplate,
messageHandler);
var batchingSink = new PeriodicBatchingSink(eventCollectorSink, batchingOptions);

return configuration.BuildPeriodicBatchingSink(eventCollectorSink, restrictedToMinimumLevel, levelSwitch,
batchIntervalInSeconds, batchSizeLimit, queueLimit);
return configuration.Sink(batchingSink, restrictedToMinimumLevel, levelSwitch);
}

/// <summary>
Expand Down Expand Up @@ -117,16 +126,25 @@ public static LoggerConfiguration EventCollector(
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
if (jsonFormatter == null) throw new ArgumentNullException(nameof(jsonFormatter));


var batchingOptions = new PeriodicBatchingSinkOptions
{
BatchSizeLimit = batchSizeLimit,
Period = TimeSpan.FromSeconds(batchIntervalInSeconds),
EagerlyEmitFirstEvent = true,
QueueLimit = queueLimit
};

var eventCollectorSink = new EventCollectorSink(
splunkHost,
eventCollectorToken,
uriPath,

jsonFormatter,
messageHandler);

return configuration.BuildPeriodicBatchingSink(eventCollectorSink, restrictedToMinimumLevel, levelSwitch,
batchIntervalInSeconds, batchSizeLimit, queueLimit);
var batchingSink = new PeriodicBatchingSink(eventCollectorSink, batchingOptions);

return configuration.Sink(batchingSink, restrictedToMinimumLevel, levelSwitch);
}


Expand Down Expand Up @@ -172,39 +190,30 @@ public static LoggerConfiguration EventCollector(
{
if (configuration == null) throw new ArgumentNullException(nameof(configuration));

var eventCollectorSink = new EventCollectorSink(
splunkHost,
eventCollectorToken,
uriPath,
source,
sourceType,
host,
index,
fields,
formatProvider,
renderTemplate,
messageHandler
);

return configuration.BuildPeriodicBatchingSink(eventCollectorSink, restrictedToMinimumLevel, levelSwitch,
batchIntervalInSeconds, batchSizeLimit, queueLimit);
}

private static LoggerConfiguration BuildPeriodicBatchingSink(this LoggerSinkConfiguration configuration,
EventCollectorSink eventCollectorSink,
LogEventLevel restrictedToMinimumLevel,
LoggingLevelSwitch levelSwitch = null,
int batchIntervalInSeconds = 2,
int batchSizeLimit = 100,
int? queueLimit = EventCollectorSink.DefaultQueueLimit)
{
var periodicBatchingOptions = new PeriodicBatchingSinkOptions
var batchingOptions = new PeriodicBatchingSinkOptions
{
Period = TimeSpan.FromSeconds(batchIntervalInSeconds), QueueLimit = queueLimit, BatchSizeLimit = batchSizeLimit
BatchSizeLimit = batchSizeLimit,
Period = TimeSpan.FromSeconds(batchIntervalInSeconds),
EagerlyEmitFirstEvent = true,
QueueLimit = queueLimit
};
var periodicBatchSink = new PeriodicBatchingSink(eventCollectorSink, periodicBatchingOptions);

return configuration.Sink(periodicBatchSink, restrictedToMinimumLevel, levelSwitch);
var eventCollectorSink = new EventCollectorSink(
splunkHost,
eventCollectorToken,
uriPath,
source,
sourceType,
host,
index,
fields,
formatProvider,
renderTemplate,
messageHandler);

var batchingSink = new PeriodicBatchingSink(eventCollectorSink, batchingOptions);

return configuration.Sink(batchingSink, restrictedToMinimumLevel, levelSwitch);
}
}
}
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.TCP/Serilog.Sinks.Splunk.TCP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.6.0" />
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.7.0" />
<PackageReference Include="Splunk.Logging.Common.Core" Version="1.0.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.UDP/Serilog.Sinks.Splunk.UDP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.6.0" />
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.7.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>Serilog.Sinks.Splunk.Tests</AssemblyName>
<PackageId>Serilog.Sinks.Splunk.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand All @@ -15,14 +15,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

Expand Down