Explorar el Código

【软件版本】
V 3.0.6.4 未发布
【模块名称】
计算http通信耗时。
【问题原因】
计算http通信耗时。
【修改描述】

【测试结果】

sat23 hace 3 años
padre
commit
4b65e17eb1
Se han modificado 2 ficheros con 25 adiciones y 1 borrados
  1. 14 1
      SCBC Factory Tools/Http/HttpHelper.cs
  2. 11 0
      SCBC Factory Tools/LogHelper/Writelog.cs

+ 14 - 1
SCBC Factory Tools/Http/HttpHelper.cs

@@ -12,6 +12,8 @@ using System.Security.Cryptography.X509Certificates;
 using System.Net.Security;
 using System.Linq;
 using System.Net.Cache;
+using System.Diagnostics;
+using SXLibrary;
 
 namespace SufeiUtil
 {
@@ -42,6 +44,9 @@ namespace SufeiUtil
         /// <returns>返回HttpResult类型</returns>
         public HttpResult GetHtml(HttpItem item)
         {
+            // 计算函数耗时;
+            Stopwatch stopwatch = new Stopwatch();
+            stopwatch.Start();
             //返回参数
             HttpResult result = new HttpResult();
             try
@@ -51,12 +56,15 @@ namespace SufeiUtil
             }
             catch (Exception ex)
             {
+                // 停止计时;
+                stopwatch.Stop();               
+                Log.WriteTimesdLog(string.Format("\r\n配置参数时出错 url={0}\r\nPostdata={1}\r\nElapsed={2}ms\r\n", item.URL, item.Postdata, stopwatch.ElapsedMilliseconds.ToString()));
+                stopwatch.Reset();
                 //配置参数时出错
                 return new HttpResult() { Cookie = string.Empty, Header = null, Html = ex.Message, StatusDescription = "配置参数时出错:" + ex.Message };
             }
             try
             {
-                
                 //请求数据
                 using (response = (HttpWebResponse)request.GetResponse())
                 {
@@ -88,6 +96,11 @@ namespace SufeiUtil
                 request = null;
                 response = null;
             }
+            // 停止计时;
+            stopwatch.Stop();           
+            Log.WriteTimesdLog(string.Format("\r\nurl={0}\r\nPostdata={1}\r\nResult={2}\r\nStatus={3}\r\nElapsed={4}ms\r\n", 
+                item.URL, item.Postdata, result.Html, result.StatusDescription, stopwatch.ElapsedMilliseconds.ToString()));
+            stopwatch.Reset();
             return result;
         }
         #endregion

+ 11 - 0
SCBC Factory Tools/LogHelper/Writelog.cs

@@ -42,6 +42,17 @@ namespace SXLibrary
             Monitor.Exit(MsgQueue);
         }
 
+        /// <summary>
+        /// 用于记录函数耗时的日志;
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void WriteTimesdLog(string msg)
+        {
+            Monitor.Enter(MsgQueue);
+            MsgQueue.Enqueue(string.Format("{0}[{1}]{2}\r\n", "Times", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"), msg));
+            Monitor.Exit(MsgQueue);
+        }
+
         public static void WriteGetKeyLog(string msg)
         {
             Monitor.Enter(MsgQueue);