2024-06-16 21:08:26 +02:00
|
|
|
using Serilog.Core;
|
|
|
|
using Serilog.Events;
|
|
|
|
|
|
|
|
namespace DotBased.Logging.Serilog;
|
|
|
|
|
|
|
|
public class BasedSerilogEnricher : ILogEventEnricher
|
|
|
|
{
|
|
|
|
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
|
|
|
|
{
|
|
|
|
var asmPropValue = "ASM";
|
|
|
|
var sourcePropValue = "Unknown";
|
|
|
|
if (logEvent.Properties.TryGetValue("SourceContext", out var sourceContextValue))
|
|
|
|
asmPropValue = sourceContextValue.ToString().Replace("\"", "");
|
|
|
|
if (logEvent.Properties.TryGetValue("Application", out var appValue))
|
|
|
|
sourcePropValue = appValue.ToString().Replace("\"", "");
|
|
|
|
|
|
|
|
var assemblyProperty = propertyFactory.CreateProperty(BasedSerilog.ExtraProperties.AssemblyProp, asmPropValue);
|
2024-11-17 22:51:54 +01:00
|
|
|
var sourceProperty = propertyFactory.CreateProperty(BasedSerilog.ExtraProperties.FullNameProp, sourcePropValue);
|
2024-06-16 21:08:26 +02:00
|
|
|
var callerProperty = propertyFactory.CreateProperty(BasedSerilog.ExtraProperties.CallerProp, sourcePropValue);
|
|
|
|
|
|
|
|
logEvent.AddPropertyIfAbsent(assemblyProperty);
|
|
|
|
logEvent.AddPropertyIfAbsent(sourceProperty);
|
|
|
|
logEvent.AddPropertyIfAbsent(callerProperty);
|
|
|
|
}
|
|
|
|
}
|