As part of my application I have a .Net Core API project. Unlike most cases where this project would run as its own process, I have the API run in a thread, among others, in a single process. Also for my project, I have implemented a custom logging system to suit my needs. However, I have come across a slight problem. Every time I run my program, once the API starts, this message is printed to the console:
Hosting environment: Production
Content root path: C:\Users\Path\To\Code
Now listening on: http://*:8000
Application started. Press Ctrl+C to shut down.
I would like to disable this message as there is no need for it, and it clutters up the otherwise well organized console log. I have a screenshot below so you know exactly what I'm talking about:
I have already disabled all other logging for the mvc (removed ILoggerFactory
from ConfigureServices
and set all logging to "None" in appsettings.json
).
How do I go about disabling/suppressing this message?
In ASP.NET Core 2.1, use the
SuppressStatusMessages
method on theWebHostBuilder
.Removing logger factory won't help, because it is Console.WriteLine() (Ref : Github issue comment) . You need to suppress the Console.WriteLine outputs. In the Main method, write code like this. This will ignore the Console.WriteLine outputs.
.NET Core 3.x
Good news! These annoying messages are not being written by ASP.NET Core using plain
Console
anymore. Now abstractLogger
is used, so startup messages will be written by your logger in configured format, just like any other logs.But if you want to get rid of these logs all along, you can use one of two following approaches
The first way is to use
.ConfigureLogging(...)
method on host builder to remove all default providers from logger:The other way is to configure .NET Core 3 logger with
ConsoleLifetimeOptions
in yourStartup.cs
:NOTE: second approach won't disable Kestrel logs about an app being listened on port (but first will)
.NET Core 2.x
These messages can be disabled in 2 ways (besides already mentioned console settings):
1) You can disable them with Environment variable:
"ASPNETCORE_SUPPRESSSTATUSMESSAGES": "true"
2) Or through code (in
Program.cs
):or
You could also do this:
This will bypass the
Console.WriteLine()
s.