Skip to content

Commit 83a220c

Browse files
authored
Merge pull request #17 from serilog/dev
3.0.1 Release
2 parents cb15532 + 65ae93d commit 83a220c

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To avoid bringing down apps with runaway disk usage the file sink **limits file
1414
.WriteTo.File("log.txt", fileSizeLimitBytes: null)
1515
```
1616

17-
> **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.
17+
> **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.
1818
1919
### `<appSettings>` configuration
2020

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

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

39+
### Shared log files
40+
41+
Multiple processes can concurrently write to the same log file if the `shared` parameter is set to `true`:
42+
43+
```csharp
44+
.WriteTo.File("log.txt", shared: true)
45+
```
46+
3947
### Performance
4048

4149
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.

src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ static LoggerConfiguration ConfigureFile(
178178

179179
if (shared)
180180
{
181-
#if !ATOMIC_APPEND
182-
throw new NotSupportedException("File sharing is not supported on this platform.");
183-
#endif
184-
181+
#if ATOMIC_APPEND
185182
if (buffered)
186183
throw new ArgumentException("Buffered writes are not available when file sharing is enabled.", nameof(buffered));
184+
#else
185+
throw new NotSupportedException("File sharing is not supported on this platform.");
186+
#endif
187187
}
188188

189189
ILogEventSink sink;
@@ -215,4 +215,4 @@ static LoggerConfiguration ConfigureFile(
215215
return addSink(sink, restrictedToMinimumLevel, levelSwitch);
216216
}
217217
}
218-
}
218+
}

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

-9
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
using System;
1616
using System.IO;
17-
#if ATOMIC_APPEND
18-
using System.Security.AccessControl;
19-
#endif
2017
using System.Text;
2118
using Serilog.Core;
2219
using Serilog.Events;
@@ -64,13 +61,7 @@ public FileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBy
6461
Directory.CreateDirectory(directory);
6562
}
6663

67-
#if ATOMIC_APPEND
68-
// FileSystemRights.AppendData improves performance substantially (~30%) when available.
69-
Stream file = new FileStream(path, FileMode.Append, FileSystemRights.AppendData, FileShare.Read, 4096, FileOptions.None);
70-
#else
7164
Stream file = System.IO.File.Open(path, FileMode.Append, FileAccess.Write, FileShare.Read);
72-
#endif
73-
7465
if (_fileSizeLimitBytes != null)
7566
{
7667
file = _countingStreamWrapper = new WriteCountingStream(file);

src/Serilog.Sinks.File/Sinks/File/SharedFileSink.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public SharedFileSink(string path, ITextFormatter textFormatter, long? fileSizeL
7575
path,
7676
FileMode.Append,
7777
FileSystemRights.AppendData,
78-
FileShare.Write,
78+
FileShare.ReadWrite,
7979
_fileStreamBufferLength,
8080
FileOptions.None);
8181

@@ -118,7 +118,7 @@ public void Emit(LogEvent logEvent)
118118
_path,
119119
FileMode.Append,
120120
FileSystemRights.AppendData,
121-
FileShare.Write,
121+
FileShare.ReadWrite,
122122
length,
123123
FileOptions.None);
124124
_fileStreamBufferLength = length;

src/Serilog.Sinks.File/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "3.0.0-*",
2+
"version": "3.0.1-*",
33
"description": "Write Serilog events to a text file in plain or JSON format.",
44
"authors": [ "Serilog Contributors" ],
55
"packOptions": {

0 commit comments

Comments
 (0)