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
parent
commit
1c7f8b8c68
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs
  2. 3
      aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging/LINGYUN/Abp/AuditLogging/AuditLogAction.cs
  3. 6
      aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs

21
aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs

@ -213,13 +213,20 @@ namespace LINGYUN.Abp.AuditLogging.Elasticsearch
var auditLog = await _converter.ConvertAsync(auditLogInfo); var auditLog = await _converter.ConvertAsync(auditLogInfo);
var response = await client.IndexAsync( //var response = await client.IndexAsync(
auditLog, // auditLog,
(x) => x.Index(CreateIndex()) // (x) => x.Index(CreateIndex())
.Id(auditLog.Id), // .Id(auditLog.Id),
cancellationToken); // cancellationToken);
return response.Id; // 使用 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( protected virtual List<Func<QueryContainerDescriptor<AuditLog>, QueryContainer>> BuildQueryDescriptor(

3
aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging/LINGYUN/Abp/AuditLogging/AuditLogAction.cs

@ -41,7 +41,8 @@ namespace LINGYUN.Abp.AuditLogging
ExtraProperties = new ExtraPropertyDictionary(actionInfo.ExtraProperties); ExtraProperties = new ExtraPropertyDictionary(actionInfo.ExtraProperties);
ServiceName = actionInfo.ServiceName; ServiceName = actionInfo.ServiceName;
MethodName = actionInfo.MethodName; MethodName = actionInfo.MethodName;
Parameters = actionInfo.Parameters.Length > 2000 ? "" : actionInfo.Parameters; Parameters = actionInfo.Parameters;
// Parameters = actionInfo.Parameters.Length > 2000 ? "" : actionInfo.Parameters;
} }
} }
} }

6
aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs

@ -90,7 +90,8 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch
(s) => s.Term( (s) => s.Term(
(t) => t.Field(GetField(nameof(SerilogInfo.Fields.UniqueId))).Value(id)), (t) => t.Field(GetField(nameof(SerilogInfo.Fields.UniqueId))).Value(id)),
(s) => s.Term( (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); cancellationToken);
} }
else else
@ -117,7 +118,8 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch
(q) => q.Bool( (q) => q.Bool(
(b) => b.Must( (b) => b.Must(
(s) => s.Term( (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); cancellationToken);
} }

Loading…
Cancel
Save