|
- using Serilog.Configuration;
- using Serilog.Core;
- using Serilog.Events;
- using Serilog;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace NearCardAttendance.TcpServer.Config
- {
- public class ThreadInfoEnricher : ILogEventEnricher
- {
- public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
- {
-
- logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadId", Thread.CurrentThread.ManagedThreadId));
- }
- }
-
- public static class EnricherExtensions
- {
- public static LoggerConfiguration WithThreadInfo(this LoggerEnrichmentConfiguration enrich)
- {
- if (enrich == null)
- throw new ArgumentNullException(nameof(enrich));
- return enrich.With<ThreadInfoEnricher>();
- }
- }
- }
|