Browse Source

Merge pull request #912 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
cfd09768b9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      aspnet-core/framework/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/AbpLoggingSerilogElasticsearchMapperProfile.cs
  2. 4
      aspnet-core/framework/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogInfo.cs

17
aspnet-core/framework/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/AbpLoggingSerilogElasticsearchMapperProfile.cs

@ -1,4 +1,5 @@
using AutoMapper; using AutoMapper;
using Serilog.Events;
namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch
{ {
@ -9,7 +10,21 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch
CreateMap<SerilogException, LogException>(); CreateMap<SerilogException, LogException>();
CreateMap<SerilogField, LogField>() CreateMap<SerilogField, LogField>()
.ForMember(log => log.Id, map => map.MapFrom(slog => slog.UniqueId.ToString())); .ForMember(log => log.Id, map => map.MapFrom(slog => slog.UniqueId.ToString()));
CreateMap<SerilogInfo, LogInfo>(); CreateMap<SerilogInfo, LogInfo>()
.ForMember(log => log.Level, map => map.MapFrom(slog => GetLogLevel(slog.Level)));
}
private static Microsoft.Extensions.Logging.LogLevel GetLogLevel(LogEventLevel logEventLevel)
{
return logEventLevel switch
{
LogEventLevel.Fatal => Microsoft.Extensions.Logging.LogLevel.Critical,
LogEventLevel.Error => Microsoft.Extensions.Logging.LogLevel.Error,
LogEventLevel.Warning => Microsoft.Extensions.Logging.LogLevel.Warning,
LogEventLevel.Information => Microsoft.Extensions.Logging.LogLevel.Information,
LogEventLevel.Debug => Microsoft.Extensions.Logging.LogLevel.Debug,
_ => Microsoft.Extensions.Logging.LogLevel.Trace,
};
} }
} }
} }

4
aspnet-core/framework/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogInfo.cs

@ -1,4 +1,4 @@
using Microsoft.Extensions.Logging; using Serilog.Events;
using Serilog.Formatting.Elasticsearch; using Serilog.Formatting.Elasticsearch;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -12,7 +12,7 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch
public DateTime TimeStamp { get; set; } public DateTime TimeStamp { get; set; }
[Nest.PropertyName(ElasticsearchJsonFormatter.LevelPropertyName)] [Nest.PropertyName(ElasticsearchJsonFormatter.LevelPropertyName)]
public LogLevel Level { get; set; } public LogEventLevel Level { get; set; }
[Nest.PropertyName(ElasticsearchJsonFormatter.RenderedMessagePropertyName)] [Nest.PropertyName(ElasticsearchJsonFormatter.RenderedMessagePropertyName)]
public string Message { get; set; } public string Message { get; set; }

Loading…
Cancel
Save