-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from serilog/dev
2.1 Release
- Loading branch information
Showing
20 changed files
with
233 additions
and
754 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
2.1.0 | ||
- Support alternative `ITextFormatter`s through the configuration API (#4) | ||
|
||
2.0.0 | ||
- Moved to new project | ||
- DotNet Core support | ||
- Moved to new project | ||
- DotNet Core support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
# Serilog.Sinks.File | ||
# 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) | ||
|
||
The file sink for Serilog. | ||
|
||
[![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/) | ||
|
||
|
||
Writes log events to a text file. | ||
Writes [Serilog](https://serilog.net) events to a text file. | ||
|
||
```csharp | ||
var log = new LoggerConfiguration() | ||
.WriteTo.File("log.txt") | ||
.CreateLogger(); | ||
``` | ||
|
||
To avoid sinking apps with runaway disk usage the file sink **limits file size to 1GB by default**. The limit can be increased or removed using the `fileSizeLimitBytes` parameter. | ||
To avoid bringing down apps with runaway disk usage the file sink **limits file size to 1GB by default**. The limit can be increased or removed using the `fileSizeLimitBytes` parameter. | ||
|
||
```csharp | ||
.WriteTo.File("log.txt", fileSizeLimitBytes: null) | ||
``` | ||
|
||
Or in XML [app-settings format](https://github.com/serilog/serilog/wiki/AppSettings): | ||
> **Important:** Only one process may write to a log file at a given time. For multi-process scenarios, either use separate files or one of the non-file-based sinks. | ||
### `<appSettings>` configuration | ||
|
||
The sink can be configured in XML [app-settings format](https://github.com/serilog/serilog/wiki/AppSettings) if the _Serilog.Settings.AppSettings_ package is in use: | ||
|
||
```xml | ||
<add key="serilog:write-to:File.path" value="log.txt" /> | ||
<add key="serilog:write-to:File.fileSizeLimitBytes" value="" /> | ||
``` | ||
|
||
> **Important:** Only one process may write to a log file at a given time. For multi-process scenarios, either use separate files or one of the non-file-based sinks. | ||
### JSON formatting | ||
|
||
To emit JSON, rather than plain text, a formatter can be specified: | ||
|
||
```csharp | ||
.WriteTo.File(new JsonFormatter(), "log.txt") | ||
``` | ||
|
||
* [Documentation](https://github.com/serilog/serilog/wiki) | ||
To configure an alternative formatter in XML `<appSettings>`, specify the formatter's assembly-qualified type name as the setting `value`. | ||
|
||
Copyright © 2016 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html). | ||
_Copyright © 2016 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.IO; | ||
using Xunit; | ||
using Serilog.Formatting.Json; | ||
using Serilog.Sinks.File.Tests.Support; | ||
using Serilog.Tests.Support; | ||
|
||
namespace Serilog.Sinks.File.Tests | ||
{ | ||
public class FileSinkTests | ||
{ | ||
[Fact] | ||
public void FileIsWrittenIfNonexistent() | ||
{ | ||
using (var tmp = TempFolder.ForCaller()) | ||
{ | ||
var nonexistent = tmp.AllocateFilename("txt"); | ||
var evt = Some.LogEvent("Hello, world!"); | ||
|
||
using (var sink = new FileSink(nonexistent, new JsonFormatter(), null)) | ||
{ | ||
sink.Emit(evt); | ||
} | ||
|
||
var lines = System.IO.File.ReadAllLines(nonexistent); | ||
Assert.Contains("Hello, world!", lines[0]); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void FileIsAppendedToWhenAlreadyCreated() | ||
{ | ||
using (var tmp = TempFolder.ForCaller()) | ||
{ | ||
var path = tmp.AllocateFilename("txt"); | ||
var evt = Some.LogEvent("Hello, world!"); | ||
|
||
using (var sink = new FileSink(path, new JsonFormatter(), null)) | ||
{ | ||
sink.Emit(evt); | ||
} | ||
|
||
using (var sink = new FileSink(path, new JsonFormatter(), null)) | ||
{ | ||
sink.Emit(evt); | ||
} | ||
|
||
var lines = System.IO.File.ReadAllLines(path); | ||
Assert.Contains("Hello, world!", lines[0]); | ||
Assert.Contains("Hello, world!", lines[1]); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void WhenLimitIsSpecifiedFileSizeIsRestricted() | ||
{ | ||
const int maxBytes = 100; | ||
|
||
using (var tmp = TempFolder.ForCaller()) | ||
{ | ||
var path = tmp.AllocateFilename("txt"); | ||
var evt = Some.LogEvent(new string('n', maxBytes + 1)); | ||
|
||
using (var sink = new FileSink(path, new JsonFormatter(), maxBytes)) | ||
{ | ||
sink.Emit(evt); | ||
} | ||
|
||
var size = new FileInfo(path).Length; | ||
Assert.True(size > 0); | ||
Assert.True(size < maxBytes); | ||
} | ||
} | ||
} | ||
} | ||
|
91 changes: 0 additions & 91 deletions
91
test/Serilog.Sinks.File.Tests/Sinks/IOFile/FileSinkTests.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.