public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { _traceWriter.TraceBeginEnd( actionExecutedContext.Request, TraceCategories.FiltersCategory, TraceLevel.Info, _innerFilter.GetType().Name, ActionExecutedMethodName, beginTrace: (tr) => { tr.Message = Error.Format( SRResources.TraceActionFilterMessage, FormattingUtilities.ActionDescriptorToString( actionExecutedContext.ActionContext.ActionDescriptor)); tr.Exception = actionExecutedContext.Exception; HttpResponseMessage response = actionExecutedContext.Response; if (response != null) { tr.Status = response.StatusCode; } }, execute: () => { _innerFilter.OnActionExecuted(actionExecutedContext); }, endTrace: (tr) => { tr.Exception = actionExecutedContext.Exception; HttpResponseMessage response = actionExecutedContext.Response; if (response != null) { tr.Status = response.StatusCode; } }, errorTrace: (tr) => { HttpResponseMessage response = actionExecutedContext.Response; if (response != null) { tr.Status = response.StatusCode; } }); }
/// <summary> /// Adds a type to a <see cref="FilterCollection" /> if it doesn't already exist. /// </summary> /// <typeparam name="TType">The type of the t type.</typeparam> /// <param name="col">The col.</param> /// <param name="order">Filter order</param> /// <returns>FilterCollection.</returns> public static FilterCollection TryAdd <TType>(this FilterCollection col, int?order = null) where TType : IFilterMetadata { var vt = typeof(TType); if (col.All(t => { // Yet more lameness, really should be able to do a simple test here... return(t switch { TypeFilterAttribute tf => tf.ImplementationType != vt, ServiceFilterAttribute sf => sf.ServiceType != vt, FormatFilterAttribute ff => ff.GetType() != vt, ResultFilterAttribute rs => rs.GetType() != vt, ExceptionFilterAttribute ef => ef.GetType() != vt, ActionFilterAttribute af => af.GetType() != vt, _ => t.GetType() != vt }); }