mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-30 06:39:27 +02:00
30 lines
875 B
C#
30 lines
875 B
C#
using Serilog.Configuration;
|
|
using Serilog;
|
|
using Serilog.Core;
|
|
using Serilog.Events;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MTWireGuard.Application
|
|
{
|
|
public class ClientIdEnricher(string clientId) : ILogEventEnricher
|
|
{
|
|
private readonly string _clientId = clientId;
|
|
|
|
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
|
|
{
|
|
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ClientId", _clientId));
|
|
}
|
|
}
|
|
|
|
public static class LoggingExtensions
|
|
{
|
|
public static LoggerConfiguration WithClientId(this LoggerEnrichmentConfiguration enrichmentConfiguration, string clientId)
|
|
{
|
|
return enrichmentConfiguration.With(new ClientIdEnricher(clientId));
|
|
}
|
|
}
|
|
}
|