`IHostBuilder` does not respect `SuppressStatusMessages` for WebHost
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
`IHostBuilder` does not respect `SuppressStatusMessages`
Create new project with `dotnet new webapi`.
Add `SuppressStatusMessages = true` for console and `builder.WebHost.SuppressStatusMessages(true);` so that we have
```lang=csharp
var builder = WebApplication.CreateBuilder(args);
builder.Host.ConfigureServices(s =>
s.Configure(o => o.SuppressStatusMessages = true));
builder.WebHost.SuppressStatusMessages(true); // <- pay attention here
```
### Expected Behavior
expected output
```
Building...
```
actual output
```
Building...
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7102
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5175
```
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
.NET SDK (reflecting any global.json):
Version: 6.0.402
Commit: 6862418796
Runtime Environment:
OS Name: Mac OS X
OS Version: 12.6
OS Platform: Darwin
RID: osx.12-x64
Base Path: /usr/local/share/dotnet/sdk/6.0.402/
global.json file:
Not found
Host:
Version: 6.0.10
Architecture: x64
Commit: 5a400c212a
### Anything else?
Also if create project with `dotnet new webapi -f net5.0` and add `webBuilder.SuppressStatusMessages(true);` so that we have
```lang=csharp
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
webBuilder.SuppressStatusMessages(true); // <- added line
});
```
then `dotnet run`.
expected output
```
Building...
```
actual output
```
Building...
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: /Users/askazakov/projects/dotnet/webapi5
```
**But** if we use `IWebHostBuilder`
```
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.SuppressStatusMessages(true)
.UseStartup();
```
everything is fine:
```
> dotnet run
Building...
```
Contributor guide
Assessment
This issue has not been assessed yet.