zoukankan      html  css  js  c++  java
  • AOP编程

    AOP工具类
    public class AroundAdvice : IMethodInterceptor
    {
    bool logurl = true;
    public AroundAdvice()
    {
    Task.Run(() => {
    logurl = WebUtils.UrlValidateCheck(SystemAddress.LogServiceUrl);
    });
    }
    public object Invoke(IMethodInvocation invocation)
    {
    string guid = Guid.NewGuid().ToString();
    object result = null;
    string actionName = invocation.TargetType.FullName + "/" + invocation.Method.Name;
    string strMessageStart = string.Format("开始-唯一标识:{0},类名:{1},方法名:{2},传参:{3}", guid, invocation.TargetType.FullName, invocation.Method.Name, Newtonsoft.Json.JsonConvert.SerializeObject(invocation.Arguments));
    try
    {
    WriteLog(invocation.TargetType.ToString(), actionName, strMessageStart);

    result = invocation.Proceed();

    string strMessageEnd = string.Format("结束-唯一标识:{0},类名:{1},方法名:{2},返回结果——请求:{3}", guid, invocation.TargetType.FullName, invocation.Method.Name, "Response:" + Newtonsoft.Json.JsonConvert.SerializeObject(result) + ",Request:" + Newtonsoft.Json.JsonConvert.SerializeObject(invocation.Arguments));
    WriteLog(invocation.TargetType.ToString(), actionName, strMessageEnd);
    }
    catch (Exception ex)
    { }


    return result;
    }

    /// <summary>
    /// 日志记录方法
    /// </summary>
    /// <param name="context"></param>
    /// <param name="actionName"></param>
    /// <param name="massage"></param>
    public void WriteLog(string messageType,string actionName, string massage)
    {
    var log = LogFactory.GetLogger(messageType);
    //bool logurl = WebUtils.UrlValidateCheck(SystemAddress.LogServiceUrl);
    if (logurl)
    {
    Task.Run(() =>
    {
    try
    {
    ExFreshLog.Instance.Info(actionName, massage + ";IP:" + Net.Ip);
    }
    catch (Exception ex)
    {
    // log.InfoByLocal(massage);
    }
    });
    }
    // else
    // log.InfoByLocal(massage);
    }
    }

  • 相关阅读:
    Linux的用户和组的属性
    Linux文件/目录 的新建、复制、移动(更名)、删除、查看、压缩命令
    排序算法和实现
    面试-三三原则
    phpstudy 最新版linux 面板 web防火墙后门防护功能教程
    小白必看的Python爬虫流程
    Python3迭代器与生成器
    python的异常处理机制
    python变量的作用域
    值得收藏的Python第三方库
  • 原文地址:https://www.cnblogs.com/badboys/p/7582054.html
Copyright © 2011-2022 走看看