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 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(

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);
ServiceName = actionInfo.ServiceName;
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(
(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);
}

Loading…
Cancel
Save