示例#1
0
        public async Task <IActionResult> DeleteLogGroups([Required][FromBody] string[] correlationIds)
        {
            List <Models.AuditLog> logsToDelete = new List <Models.AuditLog>();

            foreach (var id in correlationIds)
            {
                var logsInDb = await dbContext.AuditLogs.Where(a => a.CorrelationId == id).ToListAsync();

                if (!logsInDb.Any())
                {
                    return(BadRequest());
                }

                logsToDelete.AddRange(logsInDb);
            }

            try
            {
                dbContext.RemoveRange(logsToDelete);
                dbContext.AddAuditCustomField("Title", "Deleting logs");
                await dbContext.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw;
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostAuditLog([FromBody] AuditLog auditLog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            auditLog.AuditLogId = Guid.NewGuid();
            _context.AuditLogs.Add(auditLog);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("PostAuditLog", new { id = auditLog.AuditLogId }, auditLog.AuditLogId));
        }
示例#3
0
        public async Task Handle(AuditLogIntegrationEvent @event)
        {
            using (LogContext.PushProperty("CorrelationId", @event.CorrelationId))
            {
                _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);

                List <Models.AuditLog> logs = new List <Models.AuditLog>();
                try
                {
                    // Mapping from SharedLibraries.AuditLog (which all apps use to send logs) to Log.API.Models.AuditLog which should have same properties
                    var json = JsonConvert.SerializeObject(@event.AuditLogs);
                    logs = JsonConvert.DeserializeObject <List <Models.AuditLog> >(json);

                    await dbContext.AuditLogs.AddRangeAsync(logs);

                    await dbContext.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }