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: src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs
+87-25Lines changed: 87 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
// Copyright 2019 Serilog Contributors
1
+
// Copyright 2020 Serilog Contributors
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
@@ -13,9 +13,9 @@
13
13
// limitations under the License.
14
14
15
15
usingSystem;
16
+
usingMicrosoft.Extensions.DependencyInjection;
16
17
usingMicrosoft.Extensions.Hosting;
17
18
usingMicrosoft.Extensions.Logging;
18
-
usingMicrosoft.Extensions.DependencyInjection;
19
19
usingSerilog.Extensions.Hosting;
20
20
usingSerilog.Extensions.Logging;
21
21
@@ -26,16 +26,30 @@ namespace Serilog
26
26
/// </summary>
27
27
publicstaticclassSerilogHostBuilderExtensions
28
28
{
29
+
// Used internally to pass information through the container. We need to do this because if `logger` is the
30
+
// root logger, registering it as a singleton may lead to disposal along with the container by MEDI. This isn't
31
+
// always desirable, i.e. we may be handed a logger and `dispose: false`, so wrapping it keeps us in control
32
+
// of when the logger is disposed.
33
+
classRegisteredLogger
34
+
{
35
+
publicRegisteredLogger(ILoggerlogger)
36
+
{
37
+
Logger=logger;
38
+
}
39
+
40
+
publicILoggerLogger{get;}
41
+
}
42
+
29
43
/// <summary>
30
44
/// Sets Serilog as the logging provider.
31
45
/// </summary>
32
46
/// <param name="builder">The host builder to configure.</param>
33
47
/// <param name="logger">The Serilog logger; if not supplied, the static <see cref="Serilog.Log"/> will be used.</param>
34
48
/// <param name="dispose">When <c>true</c>, dispose <paramref name="logger"/> when the framework disposes the provider. If the
35
-
/// logger is not specified but <paramref name="dispose"/> is <c>true</c>, the <see cref="Log.CloseAndFlush()"/> method will be
36
-
/// called on the static <see cref="Log"/> class instead.</param>
49
+
/// logger is not specified but <paramref name="dispose"/> is <c>true</c>, the <see cref="Serilog.Log.CloseAndFlush()"/> method will be
50
+
/// called on the static <see cref="Serilog.Log"/> class instead.</param>
37
51
/// <param name="providers">A <see cref="LoggerProviderCollection"/> registered in the Serilog pipeline using the
38
-
/// <c>WriteTo.Providers()</c> configuration method, enabling other <see cref="ILoggerProvider"/>s to receive events. By
52
+
/// <c>WriteTo.Providers()</c> configuration method, enabling other <see cref="Microsoft.Extensions.Logging.ILoggerProvider"/>s to receive events. By
39
53
/// default, only Serilog sinks will receive events.</param>
40
54
/// <returns>The host builder.</returns>
41
55
publicstaticIHostBuilderUseSerilog(
@@ -71,14 +85,15 @@ public static IHostBuilder UseSerilog(
71
85
returnbuilder;
72
86
}
73
87
88
+
74
89
/// <summary>Sets Serilog as the logging provider.</summary>
75
90
/// <remarks>
76
91
/// A <see cref="HostBuilderContext"/> is supplied so that configuration and hosting information can be used.
77
92
/// The logger will be shut down when application services are disposed.
78
93
/// </remarks>
79
94
/// <param name="builder">The host builder to configure.</param>
80
-
/// <param name="configureLogger">The delegate for configuring the <see cref="LoggerConfiguration" /> that will be used to construct a <see cref="Microsoft.Extensions.Logging.Logger" />.</param>
81
-
/// <param name="preserveStaticLogger">Indicates whether to preserve the value of <see cref="Log.Logger"/>.</param>
95
+
/// <param name="configureLogger">The delegate for configuring the <see cref="Serilog.LoggerConfiguration" /> that will be used to construct a <see cref="Serilog.Core.Logger" />.</param>
96
+
/// <param name="preserveStaticLogger">Indicates whether to preserve the value of <see cref="Serilog.Log.Logger"/>.</param>
82
97
/// <param name="writeToProviders">By default, Serilog does not write events to <see cref="ILoggerProvider"/>s registered through
83
98
/// the Microsoft.Extensions.Logging API. Normally, equivalent Serilog sinks are used in place of providers. Specify
84
99
/// <c>true</c> to write events to all providers.</param>
@@ -91,35 +106,80 @@ public static IHostBuilder UseSerilog(
/// <summary>Sets Serilog as the logging provider.</summary>
118
+
/// <remarks>
119
+
/// A <see cref="HostBuilderContext"/> is supplied so that configuration and hosting information can be used.
120
+
/// The logger will be shut down when application services are disposed.
121
+
/// </remarks>
122
+
/// <param name="builder">The host builder to configure.</param>
123
+
/// <param name="configureLogger">The delegate for configuring the <see cref="Serilog.LoggerConfiguration" /> that will be used to construct a <see cref="Serilog.Core.Logger" />.</param>
124
+
/// <param name="preserveStaticLogger">Indicates whether to preserve the value of <see cref="Serilog.Log.Logger"/>.</param>
125
+
/// <param name="writeToProviders">By default, Serilog does not write events to <see cref="ILoggerProvider"/>s registered through
126
+
/// the Microsoft.Extensions.Logging API. Normally, equivalent Serilog sinks are used in place of providers. Specify
127
+
/// <c>true</c> to write events to all providers.</param>
0 commit comments