I have an ASP.NET Core application where I would like to hide the console lines that show up when starting the application (as I have my own welcome message)
Hosting environment: Development
Content root path: path\to\my\executable
Now listening on: http://localhost:portnumber
Application started. Press Ctrl+C to shut down.
I have attempted a solution where I set Console.Out to a null stream, and then set it back when I want to write something. It works fine for my development PC, but I've seen the issue show up on other PCs.
Console.Write(WelcomeMessage);
ConsOut = Console.Out; //Save the reference to the old out value (The terminal)
Console.SetOut(new StreamWriter(Stream.Null)); //Hack out the console
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseUrls(url)
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
I am unhappy with this solution, as it seems like a hack, and doesn't work consistently.
From How to turn off the logging done by the ASP.NET core framework, I've figured out that you can disable the automated logging system in the Configure() method of the Startup.cs class, so I believe it is something similar I am looking for, I just do not know what to do to remove the hosting messages.
EDIT: I've noticed that my question is the same as Asp.Net Core API disable startup complete message. However, it has not been given a satisfactory answer in terms of wanting to hide the startup messages, but still wanting to write my own console messages.