diff --git a/aspnet-core/framework/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs b/aspnet-core/framework/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs index 7ae475dc5..3d5548315 100644 --- a/aspnet-core/framework/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs +++ b/aspnet-core/framework/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Nest; +using Serilog.Events; using System; using System.Collections.Generic; using System.Linq; @@ -293,7 +294,7 @@ protected virtual List, QueryContaine } if (level.HasValue) { - querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Level))).Value(level.ToString()))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Level))).Value(GetLogEventLevel(level.Value).ToString()))); } if (!machineName.IsNullOrWhiteSpace()) { @@ -380,6 +381,19 @@ protected virtual string CreateIndex(DateTimeOffset? offset = null) return string.Format(_options.IndexFormat, offset.Value).ToLowerInvariant(); } + protected virtual LogEventLevel GetLogEventLevel(Microsoft.Extensions.Logging.LogLevel logLevel) + { + return logLevel switch + { + Microsoft.Extensions.Logging.LogLevel.None or Microsoft.Extensions.Logging.LogLevel.Critical => LogEventLevel.Fatal, + Microsoft.Extensions.Logging.LogLevel.Error => LogEventLevel.Error, + Microsoft.Extensions.Logging.LogLevel.Warning => LogEventLevel.Warning, + Microsoft.Extensions.Logging.LogLevel.Information => LogEventLevel.Information, + Microsoft.Extensions.Logging.LogLevel.Debug => LogEventLevel.Debug, + _ => LogEventLevel.Verbose, + }; + } + private readonly static IDictionary _fieldMaps = new Dictionary(StringComparer.InvariantCultureIgnoreCase) { { "timestamp", "@timestamp" },