Asp.Net Core API 禁用启动完成消息
作为我的应用程序的一部分,我有一个 .Net Core API 项目.与该项目作为自己的进程运行的大多数情况不同,我将 API 运行在一个线程中,尤其是在单个进程中.同样对于我的项目,我已经实现了一个自定义日志记录系统来满足我的需求.但是,我遇到了一个小问题.每次我运行我的程序时,一旦 API 启动,这条消息就会打印到控制台:
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:
我已经禁用了 mvc 的所有其他日志记录(从 ConfigureServices
中删除了 ILoggerFactory
并在 appsettings.json
中将所有日志记录设置为无">).
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?
您也可以这样做:
var host = BuildWebHost(args);
host.Start();
host.WaitForShutdown();
这将绕过Console.WriteLine()
s.