zoukankan      html  css  js  c++  java
  • C#代码执行耗时计算,此处是监测的mvc控制器方法

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011511086/article/details/78710980
    using System;
    using System.Diagnostics;
    using System.Net.Http;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Web.Http.Controllers;
    using System.Web.Mvc;

    namespace Mall.Site
    {

    /// <summary>
    /// 执行耗时监测
    /// </summary>
    public class StopwatchFilter : ActionFilterAttribute
    {
    Stopwatch wat = new Stopwatch();
    Stopwatch swAsync = new Stopwatch();

    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
    swAsync.Stop();
    if (swAsync.ElapsedMilliseconds>0)
    {
    string msg = string.Format("页面{0},线程id={1},Action执行时间{2}毫秒", filterContext.HttpContext.Request.RawUrl, Thread.CurrentThread.ManagedThreadId, swAsync.ElapsedMilliseconds);
    FrameWork.log4net.LogHelper.LogInfo(msg);
    }
    }
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
    swAsync.Reset();
    swAsync.Start();
    }


    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {
    wat.Stop();
    if (wat.ElapsedMilliseconds>0)
    {
    string msg = string.Format("页面{0},线程id={1},View执行时间{2}毫秒", filterContext.HttpContext.Request.RawUrl, Thread.CurrentThread.ManagedThreadId, wat.ElapsedMilliseconds);
    FrameWork.log4net.LogHelper.LogInfo(msg);
    }
    }
    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
    wat.Reset();
    wat.Start();
    }
    }
    }
    ---------------------
    作者:围梃狄羽
    来源:CSDN
    原文:https://blog.csdn.net/u011511086/article/details/78710980?utm_source=copy
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    SCRIPT7002: XMLHttpRequest: 网络错误 0x2efe, 由于出现错误 00002efe 而导致此项操作无法完成
    经纬转换成point的sql
    build.xml
    ubuntu下安装vsftpd及vsftpd配置文件不见的解决办法
    500 OOPS: could not read chroot() list file:/etc/vsftpd.chroot_list
    【linux】su、sudo、sudo su、sudo -i的用法和区别
    Js获取上一月份
    BigDecimal工具类
    查询重复的记录
    Excel 合并单元格
  • 原文地址:https://www.cnblogs.com/webenh/p/9796688.html
Copyright © 2011-2022 走看看