This article is a mirror article of machine translation, please click here to jump to the original article.

View: 57819|Reply: 5

[.NET Core] asp.net core writes a middleware to record the interface time

[Copy link]
Posted on 2019-9-12 17:46:02 | | | |
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






Previous:Meet Azure DevOps
Next:ID number generates snowflake algorithm
Posted on 2021-9-22 20:50:47 |
Learn to learn...
Posted on 2021-10-24 16:40:07 |
Posted on 2021-10-26 09:41:04 |
Call things, learn to learn
Posted on 2022-8-30 13:24:10 |
No. thing, learn to learn!! No. thing, learn to learn!!
Posted on 2022-8-31 13:24:59 |
learned
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com