private LogEventLevel GetLogEventLevel(AuditRecordType recordType) { switch (recordType) { case AuditRecordType.RecVoteRPCFailure: case AuditRecordType.AppendEntriesRPCFailure: return(LogEventLevel.Error); case AuditRecordType.DetectStaleTerm: return(LogEventLevel.Warning); case AuditRecordType.BecomeCandidate: case AuditRecordType.BecomeFollower: case AuditRecordType.BecomeLeader: case AuditRecordType.RecVote: case AuditRecordType.RecVoteRequest: case AuditRecordType.RejectAppendEntries: case AuditRecordType.RejectVoteRequest: case AuditRecordType.AcceptVoteRequest: return(LogEventLevel.Information); case AuditRecordType.SendHeartbeat: case AuditRecordType.RecAppendEntries: case AuditRecordType.RecHeartbeatResponse: return(LogEventLevel.Debug); default: return(LogEventLevel.Error); } }
public async Task <IEnumerable <ClientAuditLogData> > GetKycRecordsAsync(AuditRecordType recordType, DateTime from, DateTime to) { var kycStatusChanges = await _tableStorage.GetDataAsync( item => item.RecordType == recordType && item.CreatedTime >= from && item.CreatedTime <= to); var clientLogEntities = kycStatusChanges.Select(logItem => new ClientAuditLogData(logItem, logItem.ClientId)); return(clientLogEntities); }
public AuditRecord(AuditRecordType type, string candidate, RaftServerState state, int term, string extraInfo = "") { When = DateTime.Now; Type = type; Id = candidate; Term = term; ExtraInfo = extraInfo; State = state; Log.Write(GetLogEventLevel(type), "Raft audit: {@item}", this); }
private void LogAuditEntityMapLikeComponent(object entity, AuditRecordType operationType) { List <string> tempNames = new List <string>(); List <object> tempState = new List <object>(); foreach (var property in entity.GetType().GetProperties()) { if (property.Name == "Id") { continue; } tempNames.Add(property.Name); tempState.Add(property.GetValue(entity)); } this.LogAudit(entity, tempNames.ToArray(), operationType, tempState.ToArray()); }
/// <summary> /// Log insert/delete record (just one state) /// </summary> private void LogAudit( object entity, string[] propertyNames, AuditRecordType actionType, params object[] state) { string oldValue = null; string newValue = null; var curentity = entity as Item; if (curentity != null) { for (var i = 0; i < propertyNames.Count(); i++) { if (state[i] != null && IsAuditableType(state[i])) { if (IsMapLikeComponent(state[i])) { LogAuditEntityMapLikeComponent(state[i], actionType); continue; } switch (actionType) { case AuditRecordType.I: case AuditRecordType.C: newValue = (state[i] is Item) ? ((Item)state[i]).Id.ToString() : state[i].ToString(); break; case AuditRecordType.D: oldValue = (state[i] is Item) ? ((Item)state[i]).Id.ToString() : state[i].ToString(); break; default: break; } NewAuditRecord(curentity, propertyNames[i], newValue, oldValue, actionType); } } } }
public static string GeneratePk(string clientId, AuditRecordType recordType) => $"AUD_{clientId}_{(int)recordType}";
public static async Task AddAuditRecordAsync <T>(this IAuditLogRepository auditRepo, string clientId, T objBefore, T objAfter, AuditRecordType type, string changer) { var auditRecord = new AuditLogData { BeforeJson = objBefore != null?objBefore.ToJson() : null, AfterJson = objAfter != null?objAfter.ToJson() : null, CreatedTime = DateTime.UtcNow, RecordType = type, Changer = changer }; await auditRepo.InsertRecord(clientId, auditRecord); }
private void LogAuditEntityMapLikeComponent(object entity, AuditRecordType operationType) { List<string> tempNames = new List<string>(); List<object> tempState = new List<object>(); foreach (var property in entity.GetType().GetProperties()) { if (property.Name == "Id") continue; tempNames.Add(property.Name); tempState.Add(property.GetValue(entity)); } this.LogAudit(entity, tempNames.ToArray(), operationType, tempState.ToArray()); }
/// <summary> /// Creating log record and saving it to DB /// </summary> private void NewAuditRecord(Item curentity, string fieldName, string newValue, string oldValue, AuditRecordType operationType) { string entityType = curentity.GetType().ToString(); string stringTableName = entityType.Substring(entityType.LastIndexOf('.') + 1); ItemTypes tableName = ItemTypes.Undefined; Enum.TryParse(stringTableName, true, out tableName); FieldNames enumFieldName = FieldNames.Undefined; Enum.TryParse(fieldName, true, out enumFieldName); AuditLog record = new AuditLog() { AuditID = Guid.NewGuid(), EntityID = curentity.Id, AuditDate = DateTime.Now, User = currentUser.Id, TableName = tableName, FieldName = enumFieldName, NewValue = newValue, OldValue = oldValue, OwnerId = curentity.OwnerId, OperationType = operationType }; LogRepo.BeginTransaction(); LogRepo.Save(record); LogRepo.Commit(); LogRepo.Evict(record); }
public static string GeneratePartitionKey(string clientId, AuditRecordType recordType) { return($"AUD_{clientId}_{(int)recordType}"); }
private static string GenerateId(DateTime creationDt, string client, AuditRecordType recordType) { return(IdGenerator.GenerateDateTimeIdNewFirst(creationDt) + "_" + $"AUD_{client}_{(int)recordType}"); }