Browse Source
Merge pull request #602 from colinin/bulk-audit-logs
Write audit logs using the ES bulk interface
pull/645/head
5.2.2
yx lin
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
20 additions and
10 deletions
-
aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs
-
aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging/LINGYUN/Abp/AuditLogging/AuditLogAction.cs
-
aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs
|
|
|
@ -213,13 +213,20 @@ namespace LINGYUN.Abp.AuditLogging.Elasticsearch |
|
|
|
|
|
|
|
var auditLog = await _converter.ConvertAsync(auditLogInfo); |
|
|
|
|
|
|
|
var response = await client.IndexAsync( |
|
|
|
auditLog, |
|
|
|
(x) => x.Index(CreateIndex()) |
|
|
|
.Id(auditLog.Id), |
|
|
|
cancellationToken); |
|
|
|
|
|
|
|
return response.Id; |
|
|
|
//var response = await client.IndexAsync(
|
|
|
|
// auditLog,
|
|
|
|
// (x) => x.Index(CreateIndex())
|
|
|
|
// .Id(auditLog.Id),
|
|
|
|
// cancellationToken);
|
|
|
|
|
|
|
|
// 使用 Bulk 命令传输可能存在参数庞大的日志结构
|
|
|
|
var response = await client.BulkAsync( |
|
|
|
dsl => dsl.Index(CreateIndex()) |
|
|
|
.Create<AuditLog>(ct => |
|
|
|
ct.Id(auditLog.Id) |
|
|
|
.Document(auditLog))); |
|
|
|
|
|
|
|
return response.Items?.FirstOrDefault()?.Id; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual List<Func<QueryContainerDescriptor<AuditLog>, QueryContainer>> BuildQueryDescriptor( |
|
|
|
|
|
|
|
@ -41,7 +41,8 @@ namespace LINGYUN.Abp.AuditLogging |
|
|
|
ExtraProperties = new ExtraPropertyDictionary(actionInfo.ExtraProperties); |
|
|
|
ServiceName = actionInfo.ServiceName; |
|
|
|
MethodName = actionInfo.MethodName; |
|
|
|
Parameters = actionInfo.Parameters.Length > 2000 ? "" : actionInfo.Parameters; |
|
|
|
Parameters = actionInfo.Parameters; |
|
|
|
// Parameters = actionInfo.Parameters.Length > 2000 ? "" : actionInfo.Parameters;
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -90,7 +90,8 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch |
|
|
|
(s) => s.Term( |
|
|
|
(t) => t.Field(GetField(nameof(SerilogInfo.Fields.UniqueId))).Value(id)), |
|
|
|
(s) => s.Term( |
|
|
|
(t) => t.Field(GetField(nameof(SerilogInfo.Fields.TenantId))).Value(_currentTenant.GetId()))))), |
|
|
|
(t) => t.Field(GetField(nameof(SerilogInfo.Fields.TenantId))).Value(_currentTenant.GetId()))))) |
|
|
|
.Size(1), |
|
|
|
cancellationToken); |
|
|
|
} |
|
|
|
else |
|
|
|
@ -117,7 +118,8 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch |
|
|
|
(q) => q.Bool( |
|
|
|
(b) => b.Must( |
|
|
|
(s) => s.Term( |
|
|
|
(t) => t.Field(GetField(nameof(SerilogInfo.Fields.UniqueId))).Value(id))))), |
|
|
|
(t) => t.Field(GetField(nameof(SerilogInfo.Fields.UniqueId))).Value(id))))) |
|
|
|
.Size(1), |
|
|
|
cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
|