mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-31 07:09:50 +02:00
31 lines
875 B
C#
31 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));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|