public long Add(HttpLogModel model) { var result = Execute <long>(() => { model.KeyId = Guid.NewGuid(); model.CreatedAt = model.UpdatedAt = DateTime.Now; return(_repository.Add(model)); }); return(result.Data); }
public async Task InvokeAsync(HttpContext context, IHttpLoggerRepository loggerRepository) { var log = new HttpLogModel { Path = context.Request.Path, Method = context.Request.Method, QueryString = context.Request.QueryString.ToString(), IpAddress = context.Request.HttpContext.Connection.RemoteIpAddress.ToString() }; if (context.Request.Method == "POST") { context.Request.EnableBuffering(); var body = await new StreamReader(context.Request.Body) .ReadToEndAsync(); context.Request.Body.Position = 0; log.Payload = body; } log.RequestedOn = DateTime.Now; loggerRepository.Add(log); await _next(context); }
public void Add(HttpLogModel log) { using var context = new DatabaseContext(); context.Logs.Add(log); context.SaveChanges(); }