Using .NET 10
When creating a web application builder, and (trying) to suppress startup messages, I am using:
web_app_builder = Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder();
web_app_builder.Services.Configure( options =>
{
options.SuppressStatusMessages = true;
} );
The spectacular documentation for the SuppressStatusMessages method states:
Specify if startup status messages should be suppressed.
But my understanding (now) is that only a subset of "startup" messages are suppressed as there seems to be no official definition of what a "startup" message is or what categories they fall into. To be fair, the documentation does state:
suppress writing of hosting startup status messages
For example, if the code above is run WITHOUT calling the options to suppress startup messages, the following is output:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7264
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5211
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: E:\dotnet_projects\webapp1\webapp1\bin\Debug\net10.0\
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/2 GET https://localhost:7264/ - - -
info: Microsoft.AspNetCore.Http.Result.ContentResult[1]
Setting HTTP status code 200.
info: Microsoft.AspNetCore.Http.Result.ContentResult[2]
Write content with HTTP Response ContentType of text/html; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/2 GET https://localhost:7264/ - 200 - text/html;+charset=utf-8 68.7174ms
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/2 GET https://localhost:7264/_framework/aspnetcore-browser-refresh.js - - -
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/2 GET https://localhost:7264/_framework/aspnetcore-browser-refresh.js - 200 16497 application/javascript;+charset=utf-8 2.9298ms
When the code is run as shown above (WITH the option to suppress startup messages), the following is output:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7264
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5211
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/2 GET https://localhost:7264/ - - -
info: Microsoft.AspNetCore.Http.Result.ContentResult[1]
Setting HTTP status code 200.
info: Microsoft.AspNetCore.Http.Result.ContentResult[2]
Write content with HTTP Response ContentType of text/html; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/2 GET https://localhost:7264/ - 200 - text/html;+charset=utf-8 70.5674ms
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/2 GET https://localhost:7264/_framework/aspnetcore-browser-refresh.js - - -
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/2 GET https://localhost:7264/_framework/aspnetcore-browser-refresh.js - 200 16497 application/javascript;+charset=utf-8 5.4822ms
So, the only messages that are suppressed were the (hosting) messages, (the difference of WITH and WITHOUT):
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: E:\dotnet_projects\webapp1\webapp1\bin\Debug\net10.0\
But just curious - Is there any way to:
Suppress the other "startup" messages?
Have "control" over the other messages by somehow wrapping
ILoggerwith our own implementation?
My understanding is that the framework uses its own "bootstrap" logger before the host is built, so there is no way to suppress or have any control over the messages logged before the host is built - can anyone confirm this; or point to any documentation that verifies it?
Thanks in advance.