How do I enable logging for HttpClient in a .NET Core console app?

夙愿已清 提交于 2021-01-29 03:25:57

问题


.NET Core 2.2

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?

Data like this: 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


回答1:


In your appsettings.json file there will be an object which looks similar to the following:

  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  }

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.



来源:https://stackoverflow.com/questions/56170377/how-do-i-enable-logging-for-httpclient-in-a-net-core-console-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!