'How to Configure Network Tracing Dotnet core for HttpClient calls?

As per reference document at https://docs.microsoft.com/en-us/dotnet/framework/network-programming/how-to-configure-network-tracing

We can setup this in web.config or any other configuration file and we get detailed system.net traces, packets traces for HttpClient calls and any kind of issue in HttpClient calls can be captured in traces, be it certificate, TLS or anything else.

However, do we have similar implementation for dotnet core / standard which can be used in both web app or console app/ libraries ?

Configuration for dotnet framwork :

<configuration>  
  <system.diagnostics>  
    <sources>  
      <source name="System.Net" tracemode="includehex" maxdatasize="1024">  
        <listeners>  
          <add name="System.Net"/>  
        </listeners>  
      </source>  
      --------------
----------------------


Solution 1:[1]

.NET (Core) uses EventSource to record these events. On Windows the event source uses Event Tracing for Windows (ETW) so all tools that work with it can be used to record and read through the trace output. On Linux, LTTNG is used to record the events.

Microsoft's runtime repository contains documentation for Windows on how to debug network traces using both PerfView and logman. There's also documentation on capturing traces on Linux that is useful.

Microsoft is working on unifying the experience across platforms in a way. At the moment this support seems to be happening through the dotnet-trace command.

You didn't mention ASP.NET Core directly, so I will presume your question isn't specific to it, but note that as Alexandre pointed out, tracing can be configured and may provide some or all of what you need.

Solution 2:[2]

Everything is explained in the documentation : https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-2.2#logging-1.

In summary, you need to setup "Trace" logging level in appsettings.json and you should see the logs (if you register the HttpClient like this : https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-2.2#basic-usage) :

"Logging": {
    "LogLevel": {
        "Default": "Trace"
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Suchiman
Solution 2 Kaleb Pederson