public async Task Insert(HttpAudit httpAudit) { try { context.HttpAudit.Add(httpAudit); await context.SaveChangesAsync(); } catch (DbEntityValidationException e) { log.Error("Error saving HttpAudit message. " + FormatDbEntityValidationException(e), e); throw; } }
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { // read request content and make sure it doesn't disappear after consuming the string var contentType = request.Content.Headers.ContentType; var contentInString = request.Content.ReadAsStringAsync().Result; request.Content = new StringContent(contentInString); request.Content.Headers.ContentType = contentType; var response = await base.SendAsync(request, cancellationToken); var httpAudit = new HttpAudit(request, contentInString, response); await auditor.Insert(httpAudit); await base.SendAsync(request, cancellationToken); return response; }
public async Task AuditHttpTraffic(HttpAudit auditMessage) { try { context.HttpAudit.Add(auditMessage); await context.SaveChangesAsync(); } catch (Exception e) { log.Error("Exception occurred when inserting audit message to repo", e); // swallow the exception, or throw it depending on your needs/requirements throw; } }