mirror of
https://github.com/roflmuffin/CounterStrikeSharp.git
synced 2025-12-07 08:26:34 -08:00
26 lines
880 B
C#
26 lines
880 B
C#
using System.Linq;
|
|
using Serilog.Core;
|
|
using Serilog.Events;
|
|
|
|
namespace CounterStrikeSharp.API.Core.Logging;
|
|
|
|
public class SourceContextEnricher : ILogEventEnricher
|
|
{
|
|
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
|
|
{
|
|
if (logEvent.Properties.TryGetValue("SourceContext", out var property))
|
|
{
|
|
var scalarValue = property as ScalarValue;
|
|
var value = scalarValue?.Value as string;
|
|
|
|
if (value?.StartsWith("CounterStrikeSharp") ?? false)
|
|
{
|
|
var lastElement = value.Split(".").LastOrDefault();
|
|
if (!string.IsNullOrWhiteSpace(lastElement))
|
|
{
|
|
logEvent.AddOrUpdateProperty(new LogEventProperty("SourceContext", new ScalarValue(lastElement)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |