Skip to content

Commit

Permalink
Merge pull request #17 from serilog/dev
Browse files Browse the repository at this point in the history
3.0.1 Release
  • Loading branch information
nblumhardt authored Aug 31, 2016
2 parents cb15532 + 65ae93d commit 83a220c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To avoid bringing down apps with runaway disk usage the file sink **limits file
.WriteTo.File("log.txt", fileSizeLimitBytes: null)
```

> **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.
> **Important:** By default only one process may use a log file at a given time. See _Shared log files_ below if multi-process logging is required.
### `<appSettings>` configuration

Expand All @@ -36,6 +36,14 @@ To emit JSON, rather than plain text, a formatter can be specified:

To configure an alternative formatter in XML `<appSettings>`, specify the formatter's assembly-qualified type name as the setting `value`.

### Shared log files

Multiple processes can concurrently write to the same log file if the `shared` parameter is set to `true`:

```csharp
.WriteTo.File("log.txt", shared: true)
```

### Performance

By default, the file sink will flush each event written through it to disk. To improve write performance, specifying `buffered: true` will permit the underlying stream to buffer writes.
Expand Down
10 changes: 5 additions & 5 deletions src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ static LoggerConfiguration ConfigureFile(

if (shared)
{
#if !ATOMIC_APPEND
throw new NotSupportedException("File sharing is not supported on this platform.");
#endif

#if ATOMIC_APPEND
if (buffered)
throw new ArgumentException("Buffered writes are not available when file sharing is enabled.", nameof(buffered));
#else
throw new NotSupportedException("File sharing is not supported on this platform.");
#endif
}

ILogEventSink sink;
Expand Down Expand Up @@ -215,4 +215,4 @@ static LoggerConfiguration ConfigureFile(
return addSink(sink, restrictedToMinimumLevel, levelSwitch);
}
}
}
}
9 changes: 0 additions & 9 deletions src/Serilog.Sinks.File/Sinks/File/FileSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

using System;
using System.IO;
#if ATOMIC_APPEND
using System.Security.AccessControl;
#endif
using System.Text;
using Serilog.Core;
using Serilog.Events;
Expand Down Expand Up @@ -64,13 +61,7 @@ public FileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBy
Directory.CreateDirectory(directory);
}

#if ATOMIC_APPEND
// FileSystemRights.AppendData improves performance substantially (~30%) when available.
Stream file = new FileStream(path, FileMode.Append, FileSystemRights.AppendData, FileShare.Read, 4096, FileOptions.None);
#else
Stream file = System.IO.File.Open(path, FileMode.Append, FileAccess.Write, FileShare.Read);
#endif

if (_fileSizeLimitBytes != null)
{
file = _countingStreamWrapper = new WriteCountingStream(file);
Expand Down
4 changes: 2 additions & 2 deletions src/Serilog.Sinks.File/Sinks/File/SharedFileSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public SharedFileSink(string path, ITextFormatter textFormatter, long? fileSizeL
path,
FileMode.Append,
FileSystemRights.AppendData,
FileShare.Write,
FileShare.ReadWrite,
_fileStreamBufferLength,
FileOptions.None);

Expand Down Expand Up @@ -118,7 +118,7 @@ public void Emit(LogEvent logEvent)
_path,
FileMode.Append,
FileSystemRights.AppendData,
FileShare.Write,
FileShare.ReadWrite,
length,
FileOptions.None);
_fileStreamBufferLength = length;
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.File/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.0.0-*",
"version": "3.0.1-*",
"description": "Write Serilog events to a text file in plain or JSON format.",
"authors": [ "Serilog Contributors" ],
"packOptions": {
Expand Down

0 comments on commit 83a220c

Please sign in to comment.