/// <summary> /// /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { ServiceContainer.Resolve <IInitRequestScopeContext>().BeginRequest(filterContext.HttpContext.Request); if (!filterContext.HasMarkerAttribute <NonTracingAttribute>()) { var request = filterContext.HttpContext.Request; var response = filterContext.HttpContext.Response; Header reqHeader = TracingContextData.GetDefaultRequestHeader(); TracingContextData.SetSubRpcID(reqHeader.RpcID + ".0"); TracingContextData.SetRequestHeader(reqHeader); if (!filterContext.HasMarkerAttribute <NotToLogAttribute>()) { TraceLogs trace = new TraceLogs(); trace.ContextType = ContextType.Server.ToString(); trace.StartTime = DateTime.Now; trace.MachineAddr = Util.TracingContextHelper.GetServerAddress(); trace.TraceId = reqHeader.TraceID; trace.RpcId = reqHeader.RpcID; trace.Protocol = request.Url.Scheme; trace.Environment = this.environment ?? EnvironmentConfig.Environment; trace.SystemID = this.systemID ?? EnvironmentConfig.SystemID; trace.SystemName = this.systemName ?? EnvironmentConfig.SystemName; //srs.InvokeID = string.Format("{0}_{1}", filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower(), filterContext.ActionDescriptor.ActionName.ToLower()); //InvokeID trace.InvokeID = request.Url.AbsolutePath; string folder = filterContext.HttpContext.Request.Headers[Config.ResponseHeaderFolderKey]; if (!string.IsNullOrWhiteSpace(folder)) { trace.ServerHost = request.Url.Host + folder; } else { trace.ServerHost = request.Url.Host; } TraceExtensionOnActionExecuting(filterContext, trace); Util.TracingContextHelper.SetContextItem(Config.ServerRSKey, trace); } } base.OnActionExecuting(filterContext); }
public static bool TryGetAttribute <T>(this ActionExecutingContext that, bool inherit, out T test) { test = default; if (that.HasMarkerAttribute <T>()) { test = that.ActionDescriptor.GetCustomAttributes(typeof(T), inherit).Cast <T>().FirstOrDefault(); if (test == null) { test = that.Controller.GetType().GetCustomAttributes(typeof(T), inherit).Cast <T>().FirstOrDefault(); } } return(test != null); }