如何在.NET Core控制台应用程序中启用HttpClient的日志记录? [英] How do I enable logging for HttpClient in a .NET Core console app?

查看:52
本文介绍了如何在.NET Core控制台应用程序中启用HttpClient的日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.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

在.NET Framework中,您可以打开系统跟踪:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆