问题
.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