如何在.NET Core控制台应用程序中启用HttpClient的日志记录? [英] How do I enable logging for HttpClient in a .NET Core console app?
问题描述
.NET Core 2.2
我有一个使用 dotnet新控制台
创建的基本CLI.它使用 HttpClient
发出Web请求.如何查看有关这些请求的跟踪或日志记录信息?
I have a basic CLI created with dotnet new console
. It uses HttpClient
to make web requests. How can I see trace or logging information about these requests?
像这样的数据: https://www.stevejgordon.co.uk/httpclientfactory-asp-net-core-logging
In the .NET Framework, you could turn on System Tracing: https://docs.microsoft.com/en-us/dotnet/framework/network-programming/how-to-configure-network-tracing
推荐答案
在您的appsettings.json文件中,将有一个类似于以下内容的对象:
In your appsettings.json file there will be an object which looks similar to the following:
"Logging": {
"LogLevel": {
"Default": "Warning"
}
}
将日志级别增加到信息",然后再次运行您的应用程序.完成此操作后,请在 ASP中查看此页面.NET Core文档有关如何启用到文件或终端的日志记录.
Increase the log level to Information and run your application again. Once you have done that, take a look at this page in the ASP.NET Core documentation for how to enable logging to file or the terminal.
这篇关于如何在.NET Core控制台应用程序中启用HttpClient的日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!