Ejemplo n.º 1
0
        public LogRequest StartRequest()
        {
            var request = new LogRequest();

            request.Watch.Start();
            return(request);
        }
Ejemplo n.º 2
0
        private void LogToFile(LogRequest l)
        {
            var  file   = new FileInfo("log.txt");
            bool locked = true;

            while (locked)
            {
                locked = IsFileLocked(file);
            }

            var        stream = File.AppendText("log.txt");
            TextWriter w      = stream;

            w.Write("\r\nLog Entry : ");
            w.WriteLine($"{DateTime.Now.ToLongTimeString()} {DateTime.Now.ToLongDateString()}");
            w.WriteLine("  :");
            w.WriteLine($"  :How long in ms to get response {l.TimeMs.ToString()}");
            w.WriteLine($"  :The call used {l.Path.ToString()}");
            w.WriteLine($"  :The host the load balancer sends it to {l.Host.ToString()}");
            w.WriteLine("-------------------------------");
            w.Close();
            w.Dispose();
            stream.Close();
            stream.Dispose();
        }
Ejemplo n.º 3
0
        public void  StopRequest(LogRequest request)
        {
            request.Watch.Stop();

            if (this.RecordInDatabase(request))
            {
                repo.Insert(request);
            }
        }
        public async Task Invoke(HttpContext context, Log log)
        {
            if (log is null)
            {
                throw new ArgumentNullException(nameof(log));
            }

            //request

            LogRequest request = log.StartRequest();

            request.Path = context.Request.Path;
            request.Host = LoadBalancer.GetInstance().GetCurrent();
            // streamble more than once
            context.Request.EnableBuffering();
            request.Body = await new StreamReader(context.Request.Body).ReadToEndAsync();
            //read again later
            context.Request.Body.Position = 0;
            request.Method = context.Request.Method;

            var claims = context.User.Claims;
            //finds claimtype

            var origionalStream = context.Response.Body;

            var bodyBuffer = new MemoryStream();

            context.Response.Body = bodyBuffer;

            await next(context);

            // response

            if (context.Response != null)
            {
                request.StatusCode = context.Response.StatusCode;
            }
            else
            {
                request.StatusCode = 0;
            }

            bodyBuffer.Seek(0, SeekOrigin.Begin);
            var stream = context.Response.Body;

            request.ResponseBody = await new StreamReader(stream).ReadToEndAsync();

            bodyBuffer.Seek(0, SeekOrigin.Begin);
            await bodyBuffer.CopyToAsync(origionalStream);

            context.Response.Body = origionalStream;

            //ends
            log.StopRequest(request);
        }
Ejemplo n.º 5
0
 private bool RecordInDatabase(LogRequest request)
 {
     return(true);
 }
Ejemplo n.º 6
0
 public void Insert(LogRequest item)
 {
     LogToFile(item);
 }