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
+39Lines changed: 39 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,3 +86,42 @@ Tip: to see Serilog output in the Visual Studio output window when running under
86
86
### Using the package
87
87
88
88
With _Serilog.AspNetCore_ installed and configured, you can write log messages directly through Serilog or any `ILogger` interface injected by ASP.NET. All loggers will use the same underlying implementation, levels, and destinations.
89
+
90
+
### Alternative configuration
91
+
92
+
You can chose to build the logger as part of the `WebHostBuilder` pipeline, and thus benefit from the application configuration.
93
+
The following code shows an example of such a configuration:
94
+
95
+
````csharp
96
+
publicclassProgram
97
+
{
98
+
publicstaticvoidMain(string[] args)
99
+
{
100
+
varhost=newWebHostBuilder()
101
+
.UseKestrel()
102
+
.UseContentRoot(Directory.GetCurrentDirectory())
103
+
// Load the application configuration over the web host configuration.
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.
/// <summary>Sets Serilog as the logging provider.</summary>
46
+
/// <remarks>
47
+
/// A <see cref="WebHostBuilderContext"/> is supplied so that configuration and hosting information can be used.
48
+
/// The logger will be shut down when application services are disposed.
49
+
/// </remarks>
46
50
/// <param name="builder">The web host builder to configure.</param>
47
-
/// <param name="configureSerilog">The delegate for configuring the <see cref="LoggerConfiguration" /> that will be used to construct a <see cref="Logger" />.</param>
51
+
/// <param name="configureLogger">The delegate for configuring the <see cref="LoggerConfiguration" /> that will be used to construct a <see cref="Logger" />.</param>
52
+
/// <param name="preserveStaticLogger">Indicates whether to preserve the value of <see cref="Log.Logger"/>.</param>
0 commit comments