【发布时间】:2017-11-23 15:18:39
【问题描述】:
我有一个 ASP.NET Core 应用程序,我想隐藏启动应用程序时显示的控制台行(因为我有自己的欢迎消息)
Hosting environment: Development
Content root path: path\to\my\executable
Now listening on: http://localhost:portnumber
Application started. Press Ctrl+C to shut down.
我尝试了一个解决方案,将 Console.Out 设置为空流,然后在我想写东西时将其设置回来。它在我的开发 PC 上运行良好,但我在其他 PC 上看到了这个问题。
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();
我对这个解决方案不满意,因为它看起来像一个 hack,而且不能始终如一地工作。
从How to turn off the logging done by the ASP.NET core framework,我发现您可以在 Startup.cs 类的 Configure() 方法中禁用自动日志记录系统,所以我相信这是我正在寻找的类似的东西,我只是不知道如何删除托管消息。
编辑:我注意到我的问题与Asp.Net Core API disable startup complete message 相同。 但是,在想要隐藏启动消息,但仍然想编写自己的控制台消息方面尚未得到满意的答案。
【问题讨论】:
标签: c# asp.net-core