Asp.Net Core API disable startup complete message
Asp.Net Core API disable startup complete message
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:UsersPathToCode
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
).
ILoggerFactory
ConfigureServices
appsettings.json
How do I go about disabling/suppressing this message?
3 Answers
3
You could also do this:
var host = BuildWebHost(args);
host.Start();
host.WaitForShutdown();
This will bypass the Console.WriteLine()
s.
Console.WriteLine()
Just tested and it works, without making the console unusable. Thanks.
– stybl
Mar 2 at 17:15
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.
public static void Main(string args)
{
Console.SetOut(new StreamWriter(Stream.Null));
BuildWebHost(args).Run();
}
This won't do. If I do this, then nothing gets printed to the console at all. This includes my log messages. Is there a way to limit this to the API?
– stybl
May 28 '17 at 15:27
In ASP.NET Core 2.1, use the SuppressStatusMessages
method on the WebHostBuilder
.
SuppressStatusMessages
WebHostBuilder
WebHost.CreateDefaultBuilder()
.UseStartup<Startup>()
.SuppressStatusMessages(true);
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Pipe the output to /dev/null
– R. Richards
May 25 '17 at 18:02