您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

29 行
706B

  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. }