Exemple #1
0
        static void RunTest(string name, ILogTest testDef)
        {
            Console.WriteLine(name + ":");
            Stopwatch watch = Stopwatch.StartNew();
            testDef.ProduceLogs(TestSize, BufferLimit);
            watch.Stop();
            Console.WriteLine("\t produce - " + watch.ElapsedMilliseconds + "ms");
            watch.Start();
            testDef.Completed.Wait();
            watch.Stop();
            Console.WriteLine("\t total - " + watch.ElapsedMilliseconds + "ms");
            Console.WriteLine();

            GC.Collect();
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              ILogTest logTest)
        {
            logTest.Log();

            app.UseStaticFiles();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseSerilogRequestLogging(
                options =>
            {
                // X-Request-Idヘッダを追加
                options.EnrichDiagnosticContext = new RequestLoggingEnricher()
                                                  .AddCustomHeaders("X-Request-Id", "User-Agent")
                                                  .AddHttpVersion()
                                                  .Build();
            }
                );

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/x", async context =>
                {
                    Log.Information("/x called.");
                    await context.Response.WriteAsync("Hello World!");
                });

                endpoints.MapGet("/index.html", async context =>
                {
                    await context.Response.WriteAsync(@"
                      <html>
                      <head><title>test</title>
                      <script>
                      function sendSeqRequest(start) {
                          if (window.seqFailed) return;
                          var now = new Date();
                          var r = new XMLHttpRequest();                                                                     
                          r.open('post', 'http://*****:*****@t"":""' + now.toISOString() + '"",' +
                            '""@mt"":""Client Call2"",' +
                            '""Url"":""' + location.href + '"",' +
                            '""X-Request-Id"":""slkdjfsdl"",' +
                            (elapsed ? '""Elapsed"":""' + elapsed + '""' : '') +
                            '}';
                          r.send(data);
                          if (!start) {
                            r.addEventListener('load', () => {sendSeqRequest(now);}, false); 
                          }
                          var onFailure = (e) => {window.seqFailed = e.type;};
                          r.addEventListener('error', onFailure);
                          r.addEventListener('abort', onFailure);
                          r.addEventListener('timeout', onFailure);
                      }
                      function sendApiCallLog() {                                                                                   
                        sendSeqRequest();
                      }
                      </script>
                      <body>
                        test                                                                                                
                        <button onclick='sendApiCallLog()'>test</button>   
                      </body>
                      </html>
                    ");
                });
            });
        }