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
+11-35Lines changed: 11 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -89,41 +89,17 @@ With _Serilog.AspNetCore_ installed and configured, you can write log messages d
89
89
90
90
**Tip:** change the minimum level for `Microsoft` to `Warning` and plug in this [custom logging middleware](https://github.com/datalust/serilog-middleware-example/blob/master/src/Datalust.SerilogMiddlewareExample/Diagnostics/SerilogMiddleware.cs) to clean up request logging output and record more context around errors and exceptions.
91
91
92
-
### Alternative configuration
92
+
### Inline initialization
93
93
94
-
You can chose to build the logger as part of the `WebHostBuilder` pipeline, and thus benefit from the application configuration.
95
-
The following code shows an example of such a configuration:
94
+
You can alternatively configure Serilog using a delegate as shown below:
96
95
97
-
````csharp
98
-
publicclassProgram
99
-
{
100
-
publicstaticvoidMain(string[] args)
101
-
{
102
-
varhost=newWebHostBuilder()
103
-
.UseKestrel()
104
-
.UseContentRoot(Directory.GetCurrentDirectory())
105
-
// Load the application configuration over the web host configuration.
This has the advantage of making the `hostingContext`'s `Configuration` object available for configuration of the logger, but at the expense of recording `Exception`s raised earlier in program startup.
128
104
129
-
With this code, the default behavior is to set the created `ILogger` as the default logger. `Log.Logger`can be used as usual to access the created logger.
105
+
If this method is used, `Log.Logger`is assigned implicitly, and closed when the app is shut down.
0 commit comments