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);
    }
    }

  • 相关阅读:
    keep-alive的深入理解与使用(配合router-view缓存整个路由页面)
    vue无法自动打开浏览器
    解决vue页面刷新或者后退参数丢失的问题
    vue 跳转并传参,实现数据实时更新
    Struts2 有关于无法正常的使用通配符
    有关于java反编译工具的使用
    Action名称的搜索顺序
    Struts2 的 值栈和ActionContext
    在Action 中访问web资源
    oracle 创建database Link
  • 原文地址:https://www.cnblogs.com/badboys/p/7582054.html
Copyright © 2011-2022 走看看