How to Configure Network Tracing Dotnet core for HttpClient calls?

人走茶凉 提交于 2020-01-02 09:29:15

问题


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

回答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 CoreFX repository contains documentation for Windows on how to debug network traces using both PerfView and logman. Their CoreCLR repository contains documentation on capturing traces on Linux that is also 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.




回答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"
    }
}


来源:https://stackoverflow.com/questions/55477684/how-to-configure-network-tracing-dotnet-core-for-httpclient-calls

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