<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      ASP.NET Web API 接口執行時間監控

      軟件產品常常會出現這樣的情況:產品性能因某些無法預料的瓶頸而受到干擾,導致程序的處理效率降低,性能得不到充分的發揮。如何快速有效地找到軟件產品的性能瓶頸,則是我們感興趣的內容之一。

      在本文中,我將解釋我如何清理和替換重復、 混亂遍布許多方法在應用程序中的代碼使用ASP.NET Web API 的篩選器來完成ASP.NET Web API 接口執行時間監控。我們的項目中有如下的需求:我的工作相關的項目 (使用 ASP.NET Web API 框架) 要求記錄下服務接口的調用執行時間以及請求延遲、 故障率每秒的請求總數,以幫助運營團隊。 

      Web API 篩選器是你放到Action上的自定義屬性方法 (或Controller) 添加常用功能。 Web API 篩選使您得以添加預處理和后處理的行為,本文的代碼來自于How to intercept all the ASP.NET WebApi controller action methods calls with Ninject interception for logging?Log duration of an ASP Web API action

      下面是詳細代碼:

      using System;
      using System.Collections.Generic;
      using System.Diagnostics;
      using System.Linq;
      using System.Web;
      using System.Web.Http.Controllers;
      using System.Web.Http.Filters;

      namespace ContactManager.Filters
      {
          public class TimingActionFilter : ActionFilterAttribute
          {
              private const string Key = "__action_duration__";

              public override void OnActionExecuting(HttpActionContext actionContext)
              {
                  if (SkipLogging(actionContext))
                  {
                      return;
                  }
                  var stopWatch = new Stopwatch();
                  actionContext.Request.Properties[Key] = stopWatch;
                  stopWatch.Start();
              }

              public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
              {
                  if (!actionExecutedContext.Request.Properties.ContainsKey(Key))
                  {
                      return;
                  }

                  var stopWatch = actionExecutedContext.Request.Properties[Key] as Stopwatch;
                  if (stopWatch != null)
                  {
                      stopWatch.Stop();
                      var actionName = actionExecutedContext.ActionContext.ActionDescriptor.ActionName;
                      var controllerName = actionExecutedContext.ActionContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                      Debug.Print(string.Format("[Execution of{0}- {1} took {2}.]", controllerName, actionName, stopWatch.Elapsed));
                  }

              }

              private static bool SkipLogging(HttpActionContext actionContext)
              {
                  return actionContext.ActionDescriptor.GetCustomAttributes<NoLogAttribute>().Any() ||
                          actionContext.ControllerContext.ControllerDescriptor.GetCustomAttributes<NoLogAttribute>().Any();
              }

          }

          [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true)]
          public class NoLogAttribute : Attribute
          {

          }
      }

      然后在代碼里注冊 GlobalConfiguration.Configuration.Filters.Add(new TimingActionFilter());

      posted @ 2013-09-08 08:45  張善友  閱讀(14653)  評論(19)    收藏  舉報
      主站蜘蛛池模板: 亚洲美免无码中文字幕在线| 又白又嫩毛又多15p| 亚洲一区二区三区| 久久精品99国产精品亚洲| 最新的国产成人精品2020| 亚洲人成电影在线天堂色| 亚洲午夜福利网在线观看| 国产高清午夜人成在线观看,| 大地资源网中文第五页| av老司机亚洲精品天堂| 九九热在线这里只有精品| 亚洲欧美另类久久久精品播放的| 国产农村激情免费专区| 内射老阿姨1区2区3区4区| 微拍福利一区二区三区| 亚洲综合精品中文字幕| 九九热在线视频观看最新| 亚洲国产理论片在线播放| 中国性欧美videofree精品| 亚洲第一极品精品无码久久| 狠狠爱俺也去去就色| 国产专区一线二线三线码| 国产成人无码A区在线观| 福利一区二区在线观看| 久久久久国产精品人妻| 国产精品一区在线蜜臀| 亚洲天堂精品一区二区| 91蜜臀国产自产在线观看| 久久波多野结衣av| 92精品国产自产在线观看481页| 久久96热在精品国产高清| 秋霞电影院午夜无码免费视频| 国产成人无码性教育视频| 国产一区二区在线激情往| 亚洲avav天堂av在线网爱情| 波多野结衣av高清一区二区三区| 亚洲av伊人久久综合性色| 天堂亚洲免费视频| 久久亚洲熟女cc98cm| 岛国最新亚洲伦理成人| 国产精品自拍视频我看看|