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