Writing interfaces will inevitably encounter others saying that the interface is slow, how much is slower, how long does it take for an interface server to process, if there are specific numbers to record how much time each interface takes, when others say that the interface is slow, look at the interface time statistics, if it is processed in a few milliseconds, I'm sorry I don't carry this pot.
Middleware implementation asp.net core runs one middleware after another, so we only need to define our own middleware, record the time before the request starts processing and the time after the processing ends, the middleware here outputs the time of the request to the log, you can also output it to the response header or other places as needed.
Middleware configuration
To configure the request processing pipeline in Startup, the example configuration is as follows:
Search for logs by logger name "PerformanceLog" in the log, and the ElapsedMilliseconds in the log is the time consumed by the corresponding interface, or you can search by the ElapsedMilliseconds range, such as filtering logs with a time of more than 1s
|