Skip to content

Commit d4fa80a

Browse files
committed
Expose encoding to OnOpened() hook; switch to AppVeyor Linux builds
1 parent 55fcb2b commit d4fa80a

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 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)
1+
# 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)
22

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

appveyor.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
version: '{build}'
22
skip_tags: true
3-
image: Visual Studio 2017
3+
image:
4+
- Visual Studio 2017
5+
- Ubuntu
46
configuration: Release
5-
install:
6-
- ps: mkdir -Force ".\build\" | Out-Null
77
build_script:
88
- ps: ./Build.ps1
9+
for:
10+
-
11+
matrix:
12+
only:
13+
- image: Ubuntu
14+
build_script:
15+
- sh build.sh
916
test: off
1017
artifacts:
1118
- path: artifacts/Serilog.*.nupkg

build.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
#!/bin/bash
1+
#!/bin/bash
2+
3+
set -e
24
dotnet --info
5+
dotnet --list-sdks
36
dotnet restore
47

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

14+
echo "🤖 Running tests..."
915
for path in test/*.Tests/*.csproj; do
1016
dotnet test -f netcoreapp2.0 -c Release ${path}
1117
done

serilog-sinks-file.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5E1-DEB9-4A04-8BAB-24EC7240ADAF}"
99
ProjectSection(SolutionItems) = preProject
1010
.editorconfig = .editorconfig
11-
.travis.yml = .travis.yml
1211
appveyor.yml = appveyor.yml
1312
Build.ps1 = Build.ps1
1413
build.sh = build.sh

src/Serilog.Sinks.File/Sinks/File/FileLifecycleHooks.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
using System.IO;
16+
using System.Text;
1617

1718
namespace Serilog.Sinks.File
1819
{
@@ -31,7 +32,8 @@ public abstract class FileLifecycleHooks
3132
/// dispose the stream initially passed in unless it is itself returned.
3233
/// </remarks>
3334
/// <param name="underlyingStream">The underlying <see cref="Stream"/> opened on the log file.</param>
35+
/// <param name="encoding">The encoding to use when reading/writing to the stream.</param>
3436
/// <returns>The <see cref="Stream"/> Serilog should use when writing events to the log file.</returns>
35-
public virtual Stream OnOpened(Stream underlyingStream) => underlyingStream;
37+
public virtual Stream OnOpened(Stream underlyingStream, Encoding encoding) => underlyingStream;
3638
}
3739
}

src/Serilog.Sinks.File/Sinks/File/FileSink.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ internal FileSink(
7878
outputStream = _countingStreamWrapper = new WriteCountingStream(_underlyingStream);
7979
}
8080

81+
// Parameter reassignment.
82+
encoding = encoding ?? new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
83+
8184
if (hooks != null)
8285
{
83-
outputStream = hooks.OnOpened(outputStream) ??
84-
throw new InvalidOperationException($"The file lifecycle hooks `{nameof(FileLifecycleHooks.OnOpened)}()` returned `null` when called with the output stream.");
86+
outputStream = hooks.OnOpened(outputStream, encoding) ??
87+
throw new InvalidOperationException($"The file lifecycle hook `{nameof(FileLifecycleHooks.OnOpened)}(...)` returned `null`.");
8588
}
8689

87-
_output = new StreamWriter(outputStream, encoding ?? new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
90+
_output = new StreamWriter(outputStream, encoding);
8891
}
8992

9093
bool IFileSink.EmitOrOverflow(LogEvent logEvent)

test/Serilog.Sinks.File.Tests/Support/GZipHooks.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.IO;
22
using System.IO.Compression;
3+
using System.Text;
34

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

19-
public override Stream OnOpened(Stream underlyingStream)
20+
public override Stream OnOpened(Stream underlyingStream, Encoding _)
2021
{
2122
var compressStream = new GZipStream(underlyingStream, CompressionMode.Compress);
2223
return new BufferedStream(compressStream, _bufferSize);

0 commit comments

Comments
 (0)