public void GetFormatter_Returns_Null_If_Key_Predicate_Returns_True() { //Given var options = new TracingMiddlewareOptions().Ignore(key => key.StartsWith("nasty")); //When var result = options.GetFormatter("nastykey", typeof(string)); //Then Assert.Null(result); }
public void GetFormatter_Returns_Null_If_Key_In_Ignore_List() { //Given var options = new TracingMiddlewareOptions().Ignore("nastykey"); //When var result = options.GetFormatter("nastykey", typeof (string)); //Then Assert.Null(result); }
public void GetFormatter_Returns_Specified_Formatter() { //Given var options = new TracingMiddlewareOptions().ForType<int>(i => "custom formatter " + i); //When var formatter = options.GetFormatter("key", typeof(int)); var result = formatter(1); //Then Assert.Equal("custom formatter 1", result); }
public void GetFormatter_Returns_Default_Type_Formatter_If_None_Found() { //Given var options = new TracingMiddlewareOptions(); //When var formatter = options.GetFormatter("key", typeof(string)); var result = formatter("stringvalue"); //Then Assert.Equal("stringvalue",result); }
public void GetTrace_Returns_Default_Trace_If_Key_Not_Found() { //Given var list = new Dictionary<string,string>(); var options = new TracingMiddlewareOptions((id, message) => list.Add(id,message)); //When var trace = options.GetTrace("unknownkey"); trace("requestid123", "this is a default trace hopefully"); //Then Assert.True(list.ContainsKey("requestid123")); }
public void Configuration(IAppBuilder app) { //You can use defaultoptions var defaultOptions = TracingMiddlewareOptions.Default; //You can use custom options Func<IDictionary<string, object>, bool> internalexceptionfilter = environment => { var owinkvp = environment.FirstOrDefault(x => x.Key == "owin.ResponseStatusCode" && (int)x.Value == 500); return !owinkvp.Equals(default(KeyValuePair<string, object>)); }; var filters = new[] { internalexceptionfilter }; var otheroptions = new TracingMiddlewareOptions( TracingMiddlewareOptions.DefaultTrace, //Console.WriteLine or overwrite with own trace handler MessageFormat, TracingMiddlewareOptions.DefaultTypeFormat, //object.ToString() filters) .ForType<IDictionary<string, string[]>>( headers => string.Join(",", headers.Select( header => string.Format("[{0}:{1}]", header.Key, string.Join(",", header.Value))))) //Make nice with OWIN headers .ForKey("owin.ResponseStatusCode", (requestId,value) => Console.WriteLine(requestId + " : *****" + value + "*****")) //Display status code differently .Ignore<Stream>() //Ignore OWIN keys that are Stream types .Ignore(key => key.StartsWith("")) //Ignore blank keys .Include(key => key.StartsWith("owin.")); //Trace only keys that start with OWIN var alt = TracingMiddlewareOptions.Default.AddFilter(internalexceptionfilter); //Pass to your App app .Use(TracingMiddleware.Tracing(alt)) .UseNancy(); }
public static MidFunc Tracing(TracingMiddlewareOptions options = null) { options = options ?? TracingMiddlewareOptions.Default; return Tracing(() => options); }
public AppFunc CreateTracingOwinPipeline(AppFunc nextFunc, TracingMiddlewareOptions tracingMiddlewareOptions = null) { tracingMiddlewareOptions = tracingMiddlewareOptions ?? GetTracingMiddlewareOptions((s, s1) => TracingMiddlewareOptions.DefaultTrace(s, s1)); return TracingMiddleware.Tracing(tracingMiddlewareOptions)(nextFunc); }