You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+129-3
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,37 @@
2
2
3
3
Writes [Serilog](https://serilog.net) events to a set of text files, one per day.
4
4
5
-
The filename can include the `{Date}` placeholder, which will be replaced with the date of the events contained in the file.
5
+
### Getting started
6
+
7
+
Install the [Serilog.Sinks.RollingFile](https://nuget.org/packages/serilog.sinks.rollingfile) package from NuGet:
8
+
9
+
```powershell
10
+
Install-Package Serilog.Sinks.RollingFile
11
+
```
12
+
13
+
To configure the sink in C# code, call `WriteTo.RollingFile()` during logger configuration:
6
14
7
15
```csharp
8
16
varlog=newLoggerConfiguration()
9
17
.WriteTo.RollingFile("log-{Date}.txt")
10
18
.CreateLogger();
19
+
20
+
Log.Information("This will be written to the rolling file set");
21
+
```
22
+
23
+
The filename should include the `{Date}` placeholder, which will be replaced with the date of the events contained in the file. Filenames use the `yyyyMMdd` date format so that files can be ordered using a lexicographic sort:
24
+
25
+
```
26
+
log-20160631.txt
27
+
log-20160701.txt
28
+
log-20160702.txt
11
29
```
12
30
13
-
To avoid sinking apps with runaway disk usage the rolling file sink **limits file size to 1GB by default**. The limit can be changed or removed using the `fileSizeLimitBytes` parameter.
31
+
> **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](https://github.com/serilog/serilog/wiki/Provided-Sinks).
32
+
33
+
### Limits
34
+
35
+
To avoid bringing down apps with runaway disk usage the rolling file sink **limits file size to 1GB by default**. The limit can be changed or removed using the `fileSizeLimitBytes` parameter.
> **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.
47
+
### XML `<appSettings>` configuration
48
+
49
+
To use the rolling file sink with the [Serilog.Settings.AppSettings](https://github.com/serilog/serilog-settings-appsettings) package, first install that package if you haven't already done so:
50
+
51
+
```powershell
52
+
Install-Package Serilog.Settings.AppSettings
53
+
```
54
+
55
+
Instead of configuring the logger in code, call `ReadFrom.AppSettings()`:
56
+
57
+
```csharp
58
+
varlog=newLoggerConfiguration()
59
+
.ReadFrom.AppSettings()
60
+
.CreateLogger();
61
+
```
62
+
63
+
In your application's `App.config` or `Web.config` file, specify the rolling file sink assembly and required path format under the `<appSettings>` node:
The parameters that can be set through the `serilog:write-to:RollingFile` keys are the method parameters accepted by the `WriteTo.RollingFile()` configuration method. This means, for example, that the `fileSizeLimitBytes` parameter can be set with:
In XML and JSON configuration formats, environment variables can be used in setting values. This means, for instance, that the log file path can be based on `TMP` or `APPDATA`:
To use the rolling file sink with _Microsoft.Extensions.Configuration_, for example with ASP.NET Core or .NET Core, use the [Serilog.Settings.Configuration](https://github.com/serilog/serilog-settings-configuration) package. First install that package if you have not already done so:
93
+
94
+
```powershell
95
+
Install-Package Serilog.Settings.Configuration
96
+
```
97
+
98
+
Instead of configuring the rolling file directly in code, call `ReadFrom.Configuration()`:
99
+
100
+
```csharp
101
+
varconfiguration=newConfigurationBuilder()
102
+
.AddJsonFile("appsettings.json")
103
+
.Build();
104
+
105
+
varlogger=newLoggerConfiguration()
106
+
.ReadFrom.Configuration(configuration)
107
+
.CreateLogger();
108
+
```
109
+
110
+
In your `appsettings.json` file, under the `Serilog` node, :
The default rolling file sink is designed to suit most applications. So that we can keep it maintainable and reliable, it does not provide a large range of optional behavior. Check out alternative implemementations like [this one](https://github.com/BedeGaming/sinks-rollingfile) if your needs aren't met by the default version.
0 commit comments