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

5.2.0 Release #183

Merged
merged 15 commits into from
Sep 13, 2022
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
4 changes: 2 additions & 2 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --sh
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$branch-$revision"}[$branch -eq "main" -and $revision -ne "local"]

foreach ($src in ls src/Serilog.*) {
foreach ($src in gci src/Serilog.*) {
Push-Location $src

if ($suffix) {
Expand All @@ -21,7 +21,7 @@ foreach ($src in ls src/Serilog.*) {
Pop-Location
}

foreach ($test in ls test/Serilog.*.Tests) {
foreach ($test in gci test/Serilog.*.Tests) {
Push-Location $test

& dotnet test -c Release
Expand Down
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2019
image: Visual Studio 2022
install:
- ps: mkdir -Force ".\build\" | Out-Null
- pwsh: mkdir -Force ".\build\" | Out-Null
build_script:
- ps: ./Build.ps1
- pwsh: ./Build.ps1
test: off
artifacts:
- path: artifacts/Serilog.*.nupkg
Expand All @@ -17,7 +17,7 @@ deploy:
branch: /^(main|dev)$/
- provider: GitHub
auth_token:
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
secure: hX+cZmW+9BCXy7vyH8myWsYdtQHyzzil9K5yvjJv7dK9XmyrGYYDj/DPzMqsXSjo
artifact: /Serilog.*\.nupkg/
tag: v$(appveyor_build_version)
on:
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.401",
"version": "6.0.400",
"rollForward": "latestFeature"
}
}
41 changes: 26 additions & 15 deletions sample/Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
using System.Linq;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Serilog;
using Serilog.Core;

namespace Sample
{
public static class Program
{
public static void Main()
public static async Task Main()
{
// By sharing between the Seq sink and logger itself,
// Seq API keys can be used to control the level of the whole logging pipeline.
var levelSwitch = new LoggingLevelSwitch();

Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.Console()
.WriteTo.Seq("http://localhost:5341", controlLevelSwitch: levelSwitch)
.CreateLogger();
try
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.Console()
.WriteTo.Seq("http://localhost:5341", controlLevelSwitch: levelSwitch)
.CreateLogger();

Log.Information("Sample starting up");
Log.Information("Sample starting up");

foreach (var i in Enumerable.Range(0, 1000))
{
Log.Information("Running loop {Counter}, switch is at {Level}", i, levelSwitch.MinimumLevel);
foreach (var i in Enumerable.Range(0, 100))
{
Log.Information("Running loop {Counter}, switch is at {Level}", i, levelSwitch.MinimumLevel);

Thread.Sleep(1000);
Log.Debug("Loop iteration done");
Thread.Sleep(1000);
Log.Debug("Loop iteration done");
}
}
catch (Exception ex)
{
Log.Error(ex, "Unhandled exception");
}
finally
{
await Log.CloseAndFlushAsync();
}

Log.CloseAndFlush();
}
}
}
2 changes: 1 addition & 1 deletion sample/Sample/Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net4.8' ">
Expand Down
14 changes: 7 additions & 7 deletions src/Serilog.Sinks.Seq/Serilog.Sinks.Seq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>Serilog sink that writes to the Seq log server over HTTP/HTTPS.</Description>
<VersionPrefix>5.1.1</VersionPrefix>
<VersionPrefix>5.2.0</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<Copyright>Copyright © Serilog Contributors</Copyright>
<TargetFrameworks>net5.0;netstandard1.1;netstandard1.3;netstandard2.0;net4.5;netcoreapp3.1</TargetFrameworks>
Expand Down Expand Up @@ -32,11 +32,11 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<DefineConstants>$(DefineConstants);DURABLE;THREADING_TIMER;WRITE_ALL_BYTES_ASYNC</DefineConstants>
<DefineConstants>$(DefineConstants);DURABLE;THREADING_TIMER;WRITE_ALL_BYTES_ASYNC;ASYNC_DISPOSE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<DefineConstants>$(DefineConstants);DURABLE;THREADING_TIMER;WRITE_ALL_BYTES_ASYNC</DefineConstants>
<DefineConstants>$(DefineConstants);DURABLE;THREADING_TIMER;WRITE_ALL_BYTES_ASYNC;ASYNC_DISPOSE;SOCKETS_HTTP_HANDLER_ALWAYS_DEFAULT</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net4.5' ">
Expand All @@ -48,10 +48,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.3.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="3.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="All" />
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
Expand All @@ -63,7 +63,7 @@
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.1' ">
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions src/Serilog.Sinks.Seq/Sinks/Seq/Durable/DurableSeqSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
namespace Serilog.Sinks.Seq.Durable
{
sealed class DurableSeqSink : ILogEventSink, IDisposable
#if ASYNC_DISPOSE
, IAsyncDisposable
#endif
{
readonly HttpLogShipper _shipper;
readonly Logger _sink;
Expand Down Expand Up @@ -73,6 +76,14 @@ public void Dispose()
_sink.Dispose();
_shipper.Dispose();
}

#if ASYNC_DISPOSE
public async System.Threading.Tasks.ValueTask DisposeAsync()
{
await _sink.DisposeAsync().ConfigureAwait(false);
await _shipper.DisposeAsync().ConfigureAwait(false);
}
#endif

public void Emit(LogEvent logEvent)
{
Expand Down
37 changes: 26 additions & 11 deletions src/Serilog.Sinks.Seq/Sinks/Seq/Durable/HttpLogShipper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
namespace Serilog.Sinks.Seq.Durable
{
sealed class HttpLogShipper : IDisposable
#if ASYNC_DISPOSE
, IAsyncDisposable
#endif
{
static readonly TimeSpan RequiredLevelCheckInterval = TimeSpan.FromMinutes(2);

Expand Down Expand Up @@ -80,7 +83,13 @@ public HttpLogShipper(
SetTimer();
}

void CloseAndFlush()
public bool IsIncluded(LogEvent logEvent)
{
return _controlledSwitch.IsIncluded(logEvent);
}

/// <inheritdoc/>
public void Dispose()
{
lock (_stateLock)
{
Expand All @@ -92,20 +101,26 @@ void CloseAndFlush()

_timer.Dispose();

OnTick().GetAwaiter().GetResult();
Task.Run(OnTick).Wait();
}

public bool IsIncluded(LogEvent logEvent)

#if ASYNC_DISPOSE
public async ValueTask DisposeAsync()
{
return _controlledSwitch.IsIncluded(logEvent);
}
lock (_stateLock)
{
if (_unloading)
return;

/// <inheritdoc/>
public void Dispose()
{
CloseAndFlush();
}
_unloading = true;
}

_timer.Dispose();

await OnTick().ConfigureAwait(false);
}
#endif

void SetTimer()
{
// Note, called under _stateLock
Expand Down
18 changes: 17 additions & 1 deletion src/Serilog.Sinks.Seq/Sinks/Seq/Http/SeqIngestionApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,23 @@ public SeqIngestionApiClient(string serverUrl, string? apiKey, HttpMessageHandle
{
if (serverUrl == null) throw new ArgumentNullException(nameof(serverUrl));
_apiKey = apiKey;
_httpClient = messageHandler != null ? new HttpClient(messageHandler) : new HttpClient();
_httpClient = messageHandler != null
? new HttpClient(messageHandler)
:
#if SOCKETS_HTTP_HANDLER_ALWAYS_DEFAULT
new HttpClient(new SocketsHttpHandler
{
// The default value is infinite; this causes problems for long-running processes if DNS changes
// require that the Seq API be accessed at a different IP address. Setting a timeout here puts
// an upper bound on the duration of DNS-related outages, while hopefully incurring only infrequent
// connection reestablishment costs.
PooledConnectionLifetime = TimeSpan.FromMinutes(5)
})
#else
new HttpClient()
#endif
;

_httpClient.BaseAddress = new Uri(NormalizeServerBaseAddress(serverUrl));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void BatchedSinkDisposesIngestionApi()

Assert.True(api.IsDisposed);
}

[Fact]
public async Task EventsAreFormattedIntoPayloads()
{
Expand Down
2 changes: 1 addition & 1 deletion test/Serilog.Sinks.Seq.Tests/Durable/PayloadReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void ReadsEventsFromRawBufferFiles()
Assert.Equal(576 + 3 * (Environment.NewLine.Length - 1), position.NextLineStart);
Assert.Equal(fn, position.File);

var data = JsonConvert.DeserializeObject<dynamic>(payload);
var data = JsonConvert.DeserializeObject<dynamic>(payload)!;
var events = data["Events"];
Assert.NotNull(events);
Assert.Equal(3, events.Count);
Expand Down
22 changes: 17 additions & 5 deletions test/Serilog.Sinks.Seq.Tests/Serilog.Sinks.Seq.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<DefineConstants>$(DefineConstants);ASYNC_DISPOSE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<DefineConstants>$(DefineConstants);ASYNC_DISPOSE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Content Include="Resources\ThreeBufferedEvents.clef.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -23,15 +32,18 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net4.8' ">
<Reference Include="System.Net.Http" />
<PackageReference Include="System.Threading.Channels" Version="5.0.0" />
<PackageReference Include="System.Threading.Channels" Version="6.0.0" />
</ItemGroup>

</Project>