Skip to content

Commit

Permalink
Expose encoding to OnOpened() hook; switch to AppVeyor Linux builds
Browse files Browse the repository at this point in the history
  • Loading branch information
nblumhardt committed Apr 22, 2019
1 parent 55fcb2b commit d4fa80a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Serilog.Sinks.File [![Build status](https://ci.appveyor.com/api/projects/status/hh9gymy0n6tne46j?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-file) [![Travis build](https://travis-ci.org/serilog/serilog-sinks-file.svg)](https://travis-ci.org/serilog/serilog-sinks-file) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.File.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.File/) [![Documentation](https://img.shields.io/badge/docs-wiki-yellow.svg)](https://github.com/serilog/serilog/wiki) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog)
# Serilog.Sinks.File [![Build status](https://ci.appveyor.com/api/projects/status/hh9gymy0n6tne46j?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-file) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.File.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.File/) [![Documentation](https://img.shields.io/badge/docs-wiki-yellow.svg)](https://github.com/serilog/serilog/wiki) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog)

Writes [Serilog](https://serilog.net) events to one or more text files.

Expand Down
13 changes: 10 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2017
image:
- Visual Studio 2017
- Ubuntu
configuration: Release
install:
- ps: mkdir -Force ".\build\" | Out-Null
build_script:
- ps: ./Build.ps1
for:
-
matrix:
only:
- image: Ubuntu
build_script:
- sh build.sh
test: off
artifacts:
- path: artifacts/Serilog.*.nupkg
Expand Down
10 changes: 8 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/bin/bash
#!/bin/bash

set -e
dotnet --info
dotnet --list-sdks
dotnet restore

echo "🤖 Attempting to build..."
for path in src/**/*.csproj; do
dotnet build -f netstandard1.3 -c Release ${path} -p:EnableSourceLink=true
dotnet build -f netstandard1.0 -c Release ${path}
dotnet build -f netstandard1.3 -c Release ${path}
done

echo "🤖 Running tests..."
for path in test/*.Tests/*.csproj; do
dotnet test -f netcoreapp2.0 -c Release ${path}
done
1 change: 0 additions & 1 deletion serilog-sinks-file.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5E1-DEB9-4A04-8BAB-24EC7240ADAF}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
Build.ps1 = Build.ps1
build.sh = build.sh
Expand Down
4 changes: 3 additions & 1 deletion src/Serilog.Sinks.File/Sinks/File/FileLifecycleHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

using System.IO;
using System.Text;

namespace Serilog.Sinks.File
{
Expand All @@ -31,7 +32,8 @@ public abstract class FileLifecycleHooks
/// dispose the stream initially passed in unless it is itself returned.
/// </remarks>
/// <param name="underlyingStream">The underlying <see cref="Stream"/> opened on the log file.</param>
/// <param name="encoding">The encoding to use when reading/writing to the stream.</param>
/// <returns>The <see cref="Stream"/> Serilog should use when writing events to the log file.</returns>
public virtual Stream OnOpened(Stream underlyingStream) => underlyingStream;
public virtual Stream OnOpened(Stream underlyingStream, Encoding encoding) => underlyingStream;
}
}
9 changes: 6 additions & 3 deletions src/Serilog.Sinks.File/Sinks/File/FileSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ internal FileSink(
outputStream = _countingStreamWrapper = new WriteCountingStream(_underlyingStream);
}

// Parameter reassignment.
encoding = encoding ?? new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);

if (hooks != null)
{
outputStream = hooks.OnOpened(outputStream) ??
throw new InvalidOperationException($"The file lifecycle hooks `{nameof(FileLifecycleHooks.OnOpened)}()` returned `null` when called with the output stream.");
outputStream = hooks.OnOpened(outputStream, encoding) ??
throw new InvalidOperationException($"The file lifecycle hook `{nameof(FileLifecycleHooks.OnOpened)}(...)` returned `null`.");
}

_output = new StreamWriter(outputStream, encoding ?? new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
_output = new StreamWriter(outputStream, encoding);
}

bool IFileSink.EmitOrOverflow(LogEvent logEvent)
Expand Down
3 changes: 2 additions & 1 deletion test/Serilog.Sinks.File.Tests/Support/GZipHooks.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using System.IO.Compression;
using System.Text;

namespace Serilog.Sinks.File.Tests.Support
{
Expand All @@ -16,7 +17,7 @@ public GZipHooks(int bufferSize = 1024 * 32)
_bufferSize = bufferSize;
}

public override Stream OnOpened(Stream underlyingStream)
public override Stream OnOpened(Stream underlyingStream, Encoding _)
{
var compressStream = new GZipStream(underlyingStream, CompressionMode.Compress);
return new BufferedStream(compressStream, _bufferSize);
Expand Down

0 comments on commit d4fa80a

Please sign in to comment.