public override MediaTypeFormatter GetPerRequestFormatterInstance( Type type, HttpRequestMessage request, MediaTypeHeaderValue mediaType ) { MediaTypeFormatter formatter = null; TraceWriter.TraceBeginEnd( request, TraceCategories.FormattingCategory, TraceLevel.Info, InnerFormatter.GetType().Name, GetPerRequestFormatterInstanceMethodName, beginTrace: (tr) => { tr.Message = Error.Format( SRResources.TraceGetPerRequestFormatterMessage, InnerFormatter.GetType().Name, type.Name, mediaType ); }, execute: () => { formatter = InnerFormatter.GetPerRequestFormatterInstance( type, request, mediaType ); }, endTrace: (tr) => { if (formatter == null) { tr.Message = SRResources.TraceGetPerRequestNullFormatterEndMessage; } else { string formatMessage = Object.ReferenceEquals( MediaTypeFormatterTracer.ActualMediaTypeFormatter(formatter), InnerFormatter ) ? SRResources.TraceGetPerRequestFormatterEndMessage : SRResources.TraceGetPerRequestFormatterEndMessageNew; tr.Message = Error.Format(formatMessage, formatter.GetType().Name); } }, errorTrace: null ); if (formatter != null && !(formatter is IFormatterTracer)) { formatter = MediaTypeFormatterTracer.CreateTracer(formatter, TraceWriter, request); } return(formatter); }