|
12345678910111213141516171819202122232425262728 |
- using Serilog;
- using Serilog.Configuration;
- using Serilog.Core;
- using Serilog.Events;
- using System;
- using System.Threading;
-
- namespace HealthMonitor.WebApi.Configs
- {
- 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>();
- }
- }
- }
|