Browse Source

Merge pull request #911 from colinin/fixed-serilog-loglevel-mapping

Fix the serilog log level mapping
pull/914/head
yx lin 2 years ago
committed by GitHub
parent
commit
99bc38771a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      aspnet-core/framework/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs

16
aspnet-core/framework/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs

@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Nest; using Nest;
using Serilog.Events;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -293,7 +294,7 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch
} }
if (level.HasValue) 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()) if (!machineName.IsNullOrWhiteSpace())
{ {
@ -380,6 +381,19 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch
return string.Format(_options.IndexFormat, offset.Value).ToLowerInvariant(); 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<string, string> _fieldMaps = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) private readonly static IDictionary<string, string> _fieldMaps = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
{ {
{ "timestamp", "@timestamp" }, { "timestamp", "@timestamp" },

Loading…
Cancel
Save