12345678910111213141516171819202122232425 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using ArxOne.MrAdvice.Advice;
- namespace SAGA.Tools
- {
- public class WatchMethod : Attribute, IMethodAdvice
- {
- public void Advise(MethodAdviceContext context)
- {
- System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
- stopwatch.Start(); // 开始监视代码
- context.Proceed();
- stopwatch.Stop(); // 停止监视
- TimeSpan timeSpan = stopwatch.Elapsed; // 获取总时间
- double seconds = timeSpan.TotalSeconds; // 秒数
- Logs.Log($"方法 【{Name ?? context.TargetName}】耗时:{seconds}");
- }
- public string Name { get; set; }
- }
- }
|