public async Task Should_Save_An_Audit_Log() { //Arrange var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); var ipAddress = "153.1.7.61"; var firstComment = "first Comment"; var auditLog = new AuditLogInfo { UserId = userId, ImpersonatorUserId = Guid.NewGuid(), ImpersonatorTenantId = Guid.NewGuid(), ImpersonatorTenantName = "default", ImpersonatorUserName = "******", ExecutionTime = DateTime.Today, ExecutionDuration = 42, ClientIpAddress = ipAddress, ClientName = "MyDesktop", BrowserInfo = "Chrome", Comments = new List <string> { firstComment, "Second Comment" }, EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity", ChangeType = EntityChangeType.Created, ChangeTime = DateTime.Now, PropertyChanges = new List <EntityPropertyChangeInfo> { new EntityPropertyChangeInfo { PropertyTypeFullName = typeof(string).FullName, PropertyName = "Name", NewValue = "New value", OriginalValue = null } } } } }; //Act await _auditingStore.SaveAsync(auditLog); //Assert var insertedLog = (await _auditLogRepository.GetListAsync(true)) .FirstOrDefault(al => al.UserId == userId); insertedLog.ShouldNotBeNull(); insertedLog.ClientIpAddress.ShouldBe(ipAddress); insertedLog.Comments.ShouldStartWith(firstComment); insertedLog.EntityChanges.Count.ShouldBeGreaterThan(0); insertedLog.EntityChanges.First().PropertyChanges.Count.ShouldBeGreaterThan(0); }
//[Authorize(IdentityPermissions.Users.Default)] public virtual async Task <PagedResultDto <AuditLogDto> > GetListAsync(QueryAuditLogDto input) { var totalCount = await _auditLogRepository.GetCountAsync(); var list = await _auditLogRepository.GetListAsync( input.Sorting, input.MaxResultCount, input.SkipCount, input.StartTime, input.EndTime, input.HttpMethod, input.Url, input.UserName, input.ApplicationName, input.CorrelationId, input.MaxExecutionDuration, input.MinExecutionDuration, input.HasException, input.HttpStatusCode ); return(new PagedResultDto <AuditLogDto>(totalCount, list.Select(x => ObjectMapper.Map <AuditLog, AuditLogDto>(x)) .ToList())); }
public override async Task ExecuteAsync(TrafficArgs args) { var errorsCount = await _auditLogRepository.GetCountAsync( startTime : DateTime.Now.Date, endTime : DateTime.Now.Date.AddDays(1), httpStatusCode : System.Net.HttpStatusCode.InternalServerError); var errors = await _auditLogRepository.GetListAsync( startTime : DateTime.Now.Date, endTime : DateTime.Now.Date.AddDays(1), httpStatusCode : System.Net.HttpStatusCode.InternalServerError); var appErrors = errors.GroupBy(l => l.ApplicationName) .Select(l => new { ApplicationName = l.Key, Count = l.Count() }); StringBuilder sb = new StringBuilder(); sb.AppendLine($"今日总异常数:{errorsCount}"); foreach (var error in appErrors) { sb.AppendLine($"{error.ApplicationName}异常数:${error.Count}"); } var email = await GetEmailSetting(); await _smtpEmailSender.QueueAsync( from : email.from, to : email.to, subject : email.subject, sb.ToString() ); }
public async Task Should_Save_Audit_Logs_To_The_Tenant_Begins_The_Scope() { //Arrange var applicationName = Guid.NewGuid().ToString(); var tenantId = Guid.NewGuid(); var entityId1 = Guid.NewGuid(); var entityId2 = Guid.NewGuid(); //Act using (var scope = _auditingManager.BeginScope()) { _auditingManager.Current.Log.ApplicationName = applicationName; //Creating a host entity _auditingManager.Current.Log.EntityChanges.Add( new EntityChangeInfo { ChangeTime = DateTime.Now, ChangeType = EntityChangeType.Created, EntityEntry = new object(), EntityId = entityId1.ToString(), EntityTypeFullName = "TestEntity" } ); //Creating a tenant entity _auditingManager.Current.Log.EntityChanges.Add( new EntityChangeInfo { ChangeTime = DateTime.Now, ChangeType = EntityChangeType.Created, EntityEntry = new object(), EntityId = entityId2.ToString(), EntityTypeFullName = "TestEntity", EntityTenantId = tenantId } ); await scope.SaveAsync().ConfigureAwait(false); } //Assert var auditLogs = await _auditLogRepository.GetListAsync(applicationName : applicationName, includeDetails : true).ConfigureAwait(false); auditLogs.Count.ShouldBe(1); var auditLog = auditLogs.First(); auditLog.EntityChanges.ShouldNotBeNull(); auditLog.EntityChanges.Count.ShouldBe(2); auditLog.EntityChanges.ShouldContain(e => e.EntityId == entityId1.ToString()); auditLog.EntityChanges.ShouldContain(e => e.EntityId == entityId2.ToString()); }
public async Task <PagedResultDto <AuditLogDto> > GetListAsync(AuditLogInput input) { var count = (int)await _auditLogRepository.GetCountAsync(input.StartTime, input.EndTime, input.HttpMethod, input.Url, input.UserName, input.ApplicationName, input.CorrelationId, input.MaxExecutionDuration, input.MinExecutionDuration, input.HasException, input.HttpStatusCode); var list = await _auditLogRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.StartTime, input.EndTime, input.HttpMethod, input.Url, input.UserName, input.ApplicationName, input.CorrelationId, input.MaxExecutionDuration, input.MinExecutionDuration, input.HasException, input.HttpStatusCode); return(new PagedResultDto <AuditLogDto>( count, ObjectMapper.Map <List <AuditLog>, List <AuditLogDto> >(list) )); }
public async Task <PagedResultDto <AuditLogDto> > GetAll(GetAuditLogsInput input) { var count = await _auditLogRepository.GetCountAsync(httpMethod : input.HttpMethod, url : input.Url, userName : input.UserName, applicationName : input.ApplicationName, correlationId : input.CorrelationId, maxExecutionDuration : input.MaxExecutionDuration, minExecutionDuration : input.MinExecutionDuration, hasException : input.HasException, httpStatusCode : input.HttpStatusCode); var list = await _auditLogRepository.GetListAsync(sorting : input.Sorting, maxResultCount : input.MaxResultCount, skipCount : input.SkipCount, httpMethod : input.HttpMethod, url : input.Url, userName : input.UserName, applicationName : input.ApplicationName, correlationId : input.CorrelationId, maxExecutionDuration : input.MaxExecutionDuration, minExecutionDuration : input.MinExecutionDuration, hasException : input.HasException, httpStatusCode : input.HttpStatusCode); return(new PagedResultDto <AuditLogDto>( count, ObjectMapper.Map <List <AuditLog>, List <AuditLogDto> >(list) )); }
/// <summary> /// 获取审计日志 /// </summary> /// <param name="input">输入参数</param> /// <returns></returns> public async Task <Result <List <AuditLogDto> > > GetListAsync(GetAuditLogsInputDto input) { var list = await _auditingLogRepository.GetListAsync( sorting : input.Sorting, maxResultCount : input.MaxResultCount, skipCount : input.SkipCount, startTime : input.BeginTime, endTime : input.EndTime, includeDetails : true); var listDto = ObjectMapper.Map <List <AuditLog>, List <AuditLogDto> >(list); var result = new Result <List <AuditLogDto> > { Code = ResultCode.Success, Data = listDto }; return(result); }
public override async Task <PagedResultDto <AuditLogDto> > GetListAsync(GetAuditLoggingInput input) { var count = await _auditLogRepository.GetCountAsync( null, null, input.HttpMethod, input.Url, input.UserName, input.ApplicationName, input.CorrelationId, input.MaxExecutionDuration, input.MinExecutionDuration, input.HasException, input.HttpStatusCode); List <AuditLog> list = null; if (count > 0) { list = await _auditLogRepository.GetListAsync( input.Sorting, input.MaxResultCount, input.SkipCount, null, null, input.HttpMethod, input.Url, input.UserName, input.ApplicationName, input.CorrelationId, input.MaxExecutionDuration, input.MinExecutionDuration, input.HasException, input.HttpStatusCode); } return(new PagedResultDto <AuditLogDto>( count, ObjectMapper.Map <List <AuditLog>, List <AuditLogDto> >(list))); }
public async Task Should_Get_List_Of_Audit_Logs() { var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); var ipAddress = "153.1.7.61"; var firstComment = "first Comment"; var log1 = new AuditLogInfo { UserId = userId, ImpersonatorUserId = Guid.NewGuid(), ImpersonatorTenantId = Guid.NewGuid(), ExecutionTime = DateTime.Today, ExecutionDuration = 42, ClientIpAddress = ipAddress, ClientName = "MyDesktop", BrowserInfo = "Chrome", Comments = new List<string> { firstComment, "Second Comment" }, UserName = "******", EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity", ChangeType = EntityChangeType.Created, ChangeTime = DateTime.Now, PropertyChanges = new List<EntityPropertyChangeInfo> { new EntityPropertyChangeInfo { PropertyTypeFullName = typeof(string).FullName, PropertyName = "Name", NewValue = "New value", OriginalValue = null } } }, new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity", ChangeType = EntityChangeType.Created, ChangeTime = DateTime.Now, PropertyChanges = new List<EntityPropertyChangeInfo> { new EntityPropertyChangeInfo { PropertyTypeFullName = typeof(string).FullName, PropertyName = "Name", NewValue = "New value", OriginalValue = null } } } } }; var log2 = new AuditLogInfo { UserId = userId, ImpersonatorUserId = Guid.NewGuid(), ImpersonatorTenantId = Guid.NewGuid(), ExecutionTime = DateTime.Today, ExecutionDuration = 42, ClientIpAddress = ipAddress, ClientName = "MyDesktop", BrowserInfo = "Chrome", Comments = new List<string> { firstComment, "Second Comment" }, HttpStatusCode = (int?)HttpStatusCode.BadGateway, EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity", ChangeType = EntityChangeType.Created, ChangeTime = DateTime.Now, PropertyChanges = new List<EntityPropertyChangeInfo> { new EntityPropertyChangeInfo { PropertyTypeFullName = typeof(string).FullName, PropertyName = "Name", NewValue = "New value", OriginalValue = null } } } } }; await _auditingStore.SaveAsync(log1); await _auditingStore.SaveAsync(log2); var allLogsCount = await _auditLogRepository.GetCountAsync(); var onlyLog1QueryResult = await _auditLogRepository.GetListAsync(includeDetails: true, userName: "******"); var onlyLog2QueryResult = await _auditLogRepository.GetListAsync(includeDetails: true, httpStatusCode: HttpStatusCode.BadGateway); allLogsCount.ShouldBe(2); onlyLog1QueryResult.Count.ShouldBe(1); onlyLog1QueryResult.FirstOrDefault().UserName.ShouldBe("Douglas"); onlyLog1QueryResult.FirstOrDefault().EntityChanges.Count.ShouldBe(2); onlyLog2QueryResult.Count.ShouldBe(1); onlyLog2QueryResult.FirstOrDefault().HttpStatusCode.ShouldBe((int?)HttpStatusCode.BadGateway); onlyLog2QueryResult.FirstOrDefault().EntityChanges.Count.ShouldBe(1); }