You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ThreadInfoEnricher.cs 706B

1 yıl önce
12345678910111213141516171819202122232425262728
  1. using Serilog;
  2. using Serilog.Configuration;
  3. using Serilog.Core;
  4. using Serilog.Events;
  5. using System;
  6. using System.Threading;
  7. namespace HealthMonitor.WebApi.Configs
  8. {
  9. public class ThreadInfoEnricher : ILogEventEnricher
  10. {
  11. public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
  12. {
  13. logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadId", Thread.CurrentThread.ManagedThreadId));
  14. }
  15. }
  16. public static class EnricherExtensions
  17. {
  18. public static LoggerConfiguration WithThreadInfo(this LoggerEnrichmentConfiguration enrich)
  19. {
  20. if (enrich == null)
  21. throw new ArgumentNullException(nameof(enrich));
  22. return enrich.With<ThreadInfoEnricher>();
  23. }
  24. }
  25. }