Skip to content

Commit 0ced1ee

Browse files
authoredFeb 18, 2020
Merge pull request #38 from serilog/dev
2.0.0 Release
2 parents dd80bc6 + b8df615 commit 0ced1ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+428
-505
lines changed
 

‎README.md

+18-14
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ You can get started quickly with this package, and later migrate to the full Ser
1616
**1.** Add [the NuGet package](https://nuget.org/packages/serilog.extensions.logging.file) as a dependency of your project either with the package manager or directly to the CSPROJ file:
1717

1818
```xml
19-
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.1.0" />
19+
<PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />
2020
```
2121

22-
**2.** In your `Startup` class's `Configure()` method, call `AddFile()` on the provided `loggerFactory`.
22+
**2.** In your `Program` class, configure logging on the web host builder, and call `AddFile()` on the provided `loggingBuilder`.
2323

2424
```csharp
25-
public void Configure(IApplicationBuilder app,
26-
IHostingEnvironment env,
27-
ILoggerFactory loggerFactory)
25+
WebHost.CreateDefaultBuilder(args)
26+
.ConfigureLogging((hostingContext, builder) =>
2827
{
29-
loggerFactory.AddFile("Logs/myapp-{Date}.txt");
28+
builder.AddFile("Logs/myapp-{Date}.txt");
29+
})
30+
.UseStartup<Startup>()
31+
.Build();
3032
```
3133

3234
**Done!** The framework will inject `ILogger` instances into controllers and other classes:
@@ -35,12 +37,12 @@ You can get started quickly with this package, and later migrate to the full Ser
3537
class HomeController : Controller
3638
{
3739
readonly ILogger<HomeController> _log;
38-
40+
3941
public HomeController(ILogger<HomeController> log)
4042
{
4143
_log = log;
4244
}
43-
45+
4446
public IActionResult Index()
4547
{
4648
_log.LogInformation("Hello, world!");
@@ -65,12 +67,12 @@ By default, the file will be written in plain text. The fields in the log file a
6567
| **Level** | The log level assigned to the event. | Three-character code in brackets | `[INF]` |
6668
| **Message** | The log message associated with the event. | Free text | `Hello, world!` |
6769
| **Event id** | Identifies messages generated from the same format string/message template. | 32-bit hexadecimal, in parentheses | `(f83bcf75)` |
68-
| **Exception** | Exception associated with the event. | `Exception.ToString()` format (not shown) | `System.DivideByZeroException: Attempt to divide by zero\r\n\ at...` |
70+
| **Exception** | Exception associated with the event. | `Exception.ToString()` format (not shown) | `System.DivideByZeroException: Attempt to divide by zero\r\n\ at...` |
6971

7072
To record events in newline-separated JSON instead, specify `isJson: true` when configuring the logger:
7173

7274
```csharp
73-
loggerFactory.AddFile("Logs/myapp-{Date}.txt", isJson: true);
75+
loggingBuilder.AddFile("Logs/myapp-{Date}.txt", isJson: true);
7476
```
7577

7678
This will produce a log file with lines like:
@@ -113,12 +115,13 @@ The `AddFile()` method exposes some basic options for controlling the connection
113115

114116
| Parameter | Description | Example value |
115117
| --------- | ----------- | ------------- |
116-
| `pathFormat` | Filname to write. The filename may include `{Date}` to specify how the date portion of the filename is calculated. May include environment variables.| `Logs/log-{Date}.txt` |
118+
| `pathFormat` | Filename to write. The filename may include `{Date}` to specify how the date portion of the filename is calculated. May include environment variables.| `Logs/log-{Date}.txt` |
117119
| `minimumLevel` | The level below which events will be suppressed (the default is `LogLevel.Information`). | `LogLevel.Debug` |
118120
| `levelOverrides` | A dictionary mapping logger name prefixes to minimum logging levels. | |
119121
| `isJson` | If true, the log file will be written in JSON format. | `true` |
120122
| `fileSizeLimitBytes` | The maximum size, in bytes, to which any single log file will be allowed to grow. For unrestricted growth, pass`null`. The default is 1 GiB. | `1024 * 1024 * 1024` |
121123
| `retainedFileCountLimit` | The maximum number of log files that will be retained, including the current log file. For unlimited retention, pass `null`. The default is `31`. | `31` |
124+
| `outputTemplate` | The template used for formatting plain text log output. The default is `{Timestamp:o} {RequestId,13} [{Level:u3}] {Message} ({EventId:x8}){NewLine}{Exception}` | `{Timestamp:o} {RequestId,13} [{Level:u3}] {Message} {Properties:j} ({EventId:x8}){NewLine}{Exception}` |
122125

123126
### `appsettings.json` configuration
124127

@@ -141,7 +144,7 @@ In `appsettings.json` add a `"Logging"` property:
141144
And then pass the configuration section to the `AddFile()` method:
142145

143146
```csharp
144-
loggerFactory.AddFile(Configuration.GetSection("Logging"));
147+
loggingBuilder.AddFile(Configuration.GetSection("Logging"));
145148
```
146149

147150
In addition to the properties shown above, the `"Logging"` configuration supports:
@@ -151,10 +154,11 @@ In addition to the properties shown above, the `"Logging"` configuration support
151154
| `Json` | If `true`, the log file will be written in JSON format. | `true` |
152155
| `FileSizeLimitBytes` | The maximum size, in bytes, to which any single log file will be allowed to grow. For unrestricted growth, pass`null`. The default is 1 GiB. | `1024 * 1024 * 1024` |
153156
| `RetainedFileCountLimit` | The maximum number of log files that will be retained, including the current log file. For unlimited retention, pass `null`. The default is `31`. | `31` |
157+
| `OutputTemplate` | The template used for formatting plain text log output. The default is `{Timestamp:o} {RequestId,13} [{Level:u3}] {Message} ({EventId:x8}){NewLine}{Exception}` | `{Timestamp:o} {RequestId,13} [{Level:u3}] {Message} {Properties:j} ({EventId:x8}){NewLine}{Exception}` |
154158

155159
### Using the full Serilog API
156160

157-
This package is opinionated, providing the most common/recommended options supported by Serilog. For more sophisticated configuration, using Serilog directly is recommened. See the instructions in [Serilog.Extensions.Logging](https://github.com/serilog/serilog-extensions-logging) to get started.
161+
This package is opinionated, providing the most common/recommended options supported by Serilog. For more sophisticated configuration, using Serilog directly is recommened. See the instructions in [Serilog.AspNetCore](https://github.com/serilog/serilog-aspnetcore) to get started.
158162

159163
The following packages are used to provide `AddFile()`:
160164

@@ -163,5 +167,5 @@ The following packages are used to provide `AddFile()`:
163167
* [Serilog.Formatting.Compact](https://github.com/serilog/serilog-formatting-compact) - JSON event formatting
164168
* [Serilog.Extensions.Logging](https://github.com/serilog/serilog-extensions-logging) - ASP.NET Core integration
165169
* [Serilog.Sinks.Async](https://github.com/serilog/serilog-sinks-async) - async wrapper to perform log writes on a background thread
166-
170+
167171
If you decide to switch to the full Serilog API and need help, please drop into the [Gitter channel](https://gitter.im/serilog/serilog) or post your question on [Stack Overflow](http://stackoverflow.com/questions/tagged/serilog).

‎appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ artifacts:
1010
deploy:
1111
- provider: NuGet
1212
api_key:
13-
secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
13+
secure: T+8ZvBlF6teDbEuPRHVWMkuaU84MAygeuveqR4TqHbcBrW7bBOhtljzUNfiLYjfr
1414
skip_symbols: true
1515
on:
1616
branch: /^(master|dev)$/

0 commit comments

Comments
 (0)
Please sign in to comment.