Skip to content
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
52 changes: 41 additions & 11 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,51 @@
echo "build: Build started"

Push-Location $PSScriptRoot

if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
if(Test-Path .\artifacts) {
echo "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
}

& dotnet restore
& dotnet restore --no-cache

$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$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.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]

Push-Location src/Serilog.Extensions.Logging
echo "build: Version suffix is $suffix"

& dotnet pack -c Release -o ..\..\.\artifacts --version-suffix=$revision
if($LASTEXITCODE -ne 0) { exit 1 }
foreach ($src in ls src/*) {
Push-Location $src

Pop-Location
Push-Location test/Serilog.Extensions.Logging.Tests
echo "build: Packaging project in $src"

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 2 }
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
if($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
}

foreach ($test in ls test/*.PerformanceTests) {
Push-Location $test

echo "build: Building performance test project in $test"

& dotnet build -c Release
if($LASTEXITCODE -ne 0) { exit 2 }

Pop-Location
}

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

echo "build: Testing project in $test"

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 3 }

Pop-Location
}

Pop-Location
Pop-Location
11 changes: 9 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2015
configuration: Release
install:
Expand All @@ -18,5 +19,11 @@ deploy:
secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
skip_symbols: true
on:
branch: /^(dev|master)$/

branch: /^(master|dev)$/
- provider: GitHub
auth_token:
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
artifact: /Serilog.*\.nupkg/
tag: v$(appveyor_build_version)
on:
branch: master
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ class SerilogLoggerProvider : ILoggerProvider, ILogEventEnricher

// May be null; if it is, Log.Logger will be lazily used
readonly ILogger _logger;
readonly Action _dispose;

public SerilogLoggerProvider(ILogger logger = null)
public SerilogLoggerProvider(ILogger logger = null, bool dispose = false)
{
if (logger != null)
_logger = logger.ForContext(new[] { this });

if (dispose)
{
if (logger != null)
_dispose = () => (logger as IDisposable)?.Dispose();
else
_dispose = Log.CloseAndFlush;
}
}

public FrameworkLogger CreateLogger(string name)
Expand Down Expand Up @@ -77,6 +86,9 @@ public SerilogLoggerScope CurrentScope
}
#endif

public void Dispose() { }
public void Dispose()
{
_dispose?.Invoke();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ public static class SerilogLoggerFactoryExtensions
/// </summary>
/// <param name="factory">The logger factory to configure.</param>
/// <param name="logger">The Serilog logger; if not supplied, the static <see cref="Serilog.Log"/> will be used.</param>
/// <param name="dispose">When true, dispose <paramref name="logger"/> when the framework disposes the provider. If the
/// logger is not specified but <paramref name="dispose"/> is true, the <see cref="Log.CloseAndFlush()"/> method will be
/// called on the static <see cref="Log"/> class instead.</param>
/// <returns>The logger factory.</returns>
public static ILoggerFactory AddSerilog(
this ILoggerFactory factory,
ILogger logger = null)
ILogger logger = null,
bool dispose = false)
{
if (factory == null) throw new ArgumentNullException(nameof(factory));

factory.AddProvider(new SerilogLoggerProvider(logger));
factory.AddProvider(new SerilogLoggerProvider(logger, dispose));

return factory;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Extensions.Logging/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.1.0-*",
"description": "Serilog provider for Microsoft.Extensions.Logging",
"authors": [ "Microsoft", "Serilog Contributors" ],
"packOptions": {
Expand Down
19 changes: 19 additions & 0 deletions test/Serilog.Extensions.Logging.Tests/SerilogLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO;
using System.Linq;
using Serilog.Debugging;
using Serilog.Framework.Logging.Tests.Support;
using Xunit;

namespace Serilog.Extensions.Logging.Test
Expand Down Expand Up @@ -269,6 +270,24 @@ public void CarriesEventIdIfNonzero()
Assert.Equal(42, id.Value);
}

[Fact]
public void WhenDisposeIsFalseProvidedLoggerIsNotDisposed()
{
var logger = new DisposeTrackingLogger();
var provider = new SerilogLoggerProvider(logger, false);
provider.Dispose();
Assert.False(logger.IsDisposed);
}

[Fact]
public void WhenDisposeIsTrueProvidedLoggerIsDisposed()
{
var logger = new DisposeTrackingLogger();
var provider = new SerilogLoggerProvider(logger, true);
provider.Dispose();
Assert.True(logger.IsDisposed);
}

private class FoodScope : IEnumerable<KeyValuePair<string, object>>
{
readonly string _name;
Expand Down
Loading