Skip to content

Commit 9c017cd

Browse files
authored
Move generic webhost log output, enable in templates (#6814)
1 parent 3dbf5d2 commit 9c017cd

File tree

9 files changed

+24
-13
lines changed

9 files changed

+24
-13
lines changed

src/Hosting/Hosting/src/GenericHost/GenericWebHostedService.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -27,7 +27,7 @@ internal class GenericWebHostService : IHostedService
2727
{
2828
public GenericWebHostService(IOptions<GenericWebHostServiceOptions> options,
2929
IServer server,
30-
ILogger<GenericWebHostService> logger,
30+
ILoggerFactory loggerFactory,
3131
DiagnosticListener diagnosticListener,
3232
IHttpContextFactory httpContextFactory,
3333
IApplicationBuilderFactory applicationBuilderFactory,
@@ -37,7 +37,8 @@ public GenericWebHostService(IOptions<GenericWebHostServiceOptions> options,
3737
{
3838
Options = options.Value;
3939
Server = server;
40-
Logger = logger;
40+
Logger = loggerFactory.CreateLogger<GenericWebHostService>();
41+
LifetimeLogger = loggerFactory.CreateLogger("Microsoft.Hosting.Lifetime");
4142
DiagnosticListener = diagnosticListener;
4243
HttpContextFactory = httpContextFactory;
4344
ApplicationBuilderFactory = applicationBuilderFactory;
@@ -49,6 +50,8 @@ public GenericWebHostService(IOptions<GenericWebHostServiceOptions> options,
4950
public GenericWebHostServiceOptions Options { get; }
5051
public IServer Server { get; }
5152
public ILogger<GenericWebHostService> Logger { get; }
53+
// Only for high level lifetime events
54+
public ILogger LifetimeLogger { get; }
5255
public DiagnosticListener DiagnosticListener { get; }
5356
public IHttpContextFactory HttpContextFactory { get; }
5457
public IApplicationBuilderFactory ApplicationBuilderFactory { get; }
@@ -119,7 +122,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
119122
{
120123
foreach (var address in addresses)
121124
{
122-
Logger.LogInformation("Now listening on: {address}", address);
125+
LifetimeLogger.LogInformation("Now listening on: {address}", address);
123126
}
124127
}
125128

@@ -198,4 +201,4 @@ public async Task StopAsync(CancellationToken cancellationToken)
198201
}
199202
}
200203
}
201-
}
204+
}

src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-CSharp/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Warning"
4+
"Default": "Warning",
5+
"Microsoft.Hosting.Lifetime": "Information"
56
}
67
},
78
"AllowedHosts": "*"

src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-FSharp/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Warning"
4+
"Default": "Warning",
5+
"Microsoft.Hosting.Lifetime": "Information"
56
}
67
},
78
"AllowedHosts": "*"

src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorComponentsWeb-CSharp/RazorComponentsWeb-CSharp.Server/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Warning"
4+
"Default": "Warning",
5+
"Microsoft.Hosting.Lifetime": "Information"
56
}
67
},
78
"AllowedHosts": "*"

src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
//#endif
3434
"Logging": {
3535
"LogLevel": {
36-
"Default": "Warning"
36+
"Default": "Warning",
37+
"Microsoft.Hosting.Lifetime": "Information"
3738
}
3839
},
3940
"AllowedHosts": "*"

src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
//#endif
3434
"Logging": {
3535
"LogLevel": {
36-
"Default": "Warning"
36+
"Default": "Warning",
37+
"Microsoft.Hosting.Lifetime": "Information"
3738
}
3839
},
3940
"AllowedHosts": "*"

src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-FSharp/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Warning"
4+
"Default": "Warning",
5+
"Microsoft.Hosting.Lifetime": "Information"
56
}
67
},
78
"AllowedHosts": "*"

src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-CSharp/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
//#endif
2121
"Logging": {
2222
"LogLevel": {
23-
"Default": "Warning"
23+
"Default": "Warning",
24+
"Microsoft.Hosting.Lifetime": "Information"
2425
}
2526
},
2627
"AllowedHosts": "*"

src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-FSharp/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Warning"
4+
"Default": "Warning",
5+
"Microsoft.Hosting.Lifetime": "Information"
56
}
67
},
78
"AllowedHosts": "*"

0 commit comments

Comments
 (0)