Skip to content

Commit 8651ec7

Browse files
authored
Some slight README organization tweaks
1 parent 32fde1d commit 8651ec7

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ That's it! With the level bumped up a little you will see log output resembling:
8282

8383
A more complete example, showing `appsettings.json` configuration, can be found in [the sample project here](https://github.com/serilog/serilog-aspnetcore/tree/dev/samples/EarlyInitializationSample).
8484

85-
### Request logging <sup>`3.0.0-*`</sup>
85+
### Request logging <sup>`3.0.0`</sup>
8686

8787
The package includes middleware for smarter HTTP request logging. The default request logging implemented by ASP.NET Core is noisy, with multiple events emitted per request. The included middleware condenses these into a single event that carries method, path, status code, and timing information.
8888

@@ -134,7 +134,7 @@ Then, in your application's _Startup.cs_, add the middleware with `UseSerilogReq
134134
// Other app configuration
135135
```
136136

137-
It's important that the `UseSerilogRequestLogging()` call appears _before_ handlers such as MVC. The middleware will not time or log components that appear before it in the pipeline. You can override the message template by specifying `messageTemplate`. (This can be utilized to exclude noisy handlers from logging, such as `UseStaticFiles()`, by placing `UseSerilogRequestLogging()` after them.)
137+
It's important that the `UseSerilogRequestLogging()` call appears _before_ handlers such as MVC. The middleware will not time or log components that appear before it in the pipeline. (This can be utilized to exclude noisy handlers from logging, such as `UseStaticFiles()`, by placing `UseSerilogRequestLogging()` after them.)
138138

139139
During request processing, additional properties can be attached to the completion event using `IDiagnosticContext.Set()`:
140140

@@ -159,18 +159,25 @@ During request processing, additional properties can be attached to the completi
159159

160160
This pattern has the advantage of reducing the number of log events that need to be constructed, transmitted, and stored per HTTP request. Having many properties on the same event can also make correlation of request details and other data easier.
161161

162-
The following request information will be added as log properties:
162+
The following request information will be added as properties by default:
163163

164164
* `RequestMethod`
165165
* `RequestPath`
166166
* `StatusCode`
167167
* `Elapsed`
168168

169-
Not enough? You can extend the information that is being emitted by using `options.EnrichDiagnosticContext`:
169+
You can modify the message template used for request completion events, add additional properties, or change the event level, using the `options` callback on `UseSerilogRequestLogging()`:
170170

171171
```csharp
172172
app.UseSerilogRequestLogging(options =>
173173
{
174+
// Customize the message template
175+
options.MessageTemplate = "Handled {RequestPath}";
176+
177+
// Emit debug-level events instead of the defaults
178+
options.GetLevel = (httpContext, elapsed, ex) => LogEventLevel.Debug;
179+
180+
// Attach additional properties to the request completion event
174181
options.EnrichDiagnosticContext = (diagnosticContext, httpContext) =>
175182
{
176183
diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value);

0 commit comments

Comments
 (0)