Example #1
1
 static async void DoItLogging()
 {
     var middleware = new HttpEventCollectorResendMiddleware(100);
     var ecSender = new HttpEventCollectorSender(new Uri("https://localhost:8088"),
         "3E712E99-63C5-4C5A-841D-592DD070DA51",
         null,
         HttpEventCollectorSender.SendMode.Sequential,
         0,
         0,
         0,
         middleware.Plugin
     );
     ecSender.OnError += o => Console.WriteLine(o.Message);
     ecSender.Send(Guid.NewGuid().ToString(), "INFO", null, new { Foo = "Bar" });
     dynamic obj = new JObject();
     obj.Bar = "Baz";
     ecSender.Send(Guid.NewGuid().ToString(), "INFO", null, (JObject)obj);
     await ecSender.FlushAsync();
 }
        public void HttpEventCollectorResendTest()
        {
            int resendCount = 0;
            HttpEventCollectorResendMiddleware resend = new HttpEventCollectorResendMiddleware(3);
            var trace = Trace(
                handler: (auth, input) =>
            {
                resendCount++;
                // mimic server error, this problem is considered as "fixable"
                // by resend middleware
                return(new Response(HttpStatusCode.InternalServerError, "{\"text\":\"Error\"}"));
            },
                middleware: (new HttpEventCollectorResendMiddleware(3)).Plugin // repeat 3 times
                );

            (trace.Listeners[trace.Listeners.Count - 1] as HttpEventCollectorTraceListener).AddLoggingFailureHandler(
                (exception) =>
            {
                // error handler should be called after a single "normal post" and 3 "retries"
                Assert.True(resendCount == 4);

                // check exception events
                Assert.True(exception.Events.Count == 1);
                Assert.True(exception.Events[0].Event.Message == "info");
            });
            trace.TraceInformation("info");
            trace.Close();
        }
        public void HttpEventCollectorResendTest()
        {
            int resendCount = 0;
            HttpEventCollectorResendMiddleware resend = new HttpEventCollectorResendMiddleware(3);
            var trace = Trace(
                handler: (auth, input) =>
                {
                    resendCount++;
                    // mimic server error, this problem is considered as "fixable"
                    // by resend middleware
                    return new Response(HttpStatusCode.InternalServerError, "{\"text\":\"Error\"}");
                },
                middleware: (new HttpEventCollectorResendMiddleware(3)).Plugin // repeat 3 times
            );
            (trace.Listeners[trace.Listeners.Count-1] as HttpEventCollectorTraceListener).AddLoggingFailureHandler(
                (exception) =>
                {
                    // error handler should be called after a single "normal post" and 3 "retries"
                    Assert.True(resendCount == 4);

                    // check exception events
                    Assert.True(exception.Events.Count == 1);
                    Assert.True(exception.Events[0].Event.Message == "info");
                });
            trace.TraceInformation("info");
            trace.Close();
        }