MonitorManager.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Grpc.Extension.BaseService
  5. {
  6. public class MonitorManager
  7. {
  8. private static readonly object syncSaveResponseMethods = new object();
  9. private static List<string> saveResponseMethods = new List<string>();
  10. private static readonly Lazy<MonitorManager> instance = new Lazy<MonitorManager>(() => new MonitorManager(), true);
  11. public static MonitorManager Instance
  12. {
  13. get { return instance.Value; }
  14. }
  15. #region 是否记录响应数据到日志
  16. public void AddSaveResponseMethod(string fullName)
  17. {
  18. if (string.IsNullOrWhiteSpace(fullName)) return;
  19. lock (syncSaveResponseMethods)
  20. {
  21. saveResponseMethods.Add(fullName);
  22. saveResponseMethods = saveResponseMethods.Distinct().ToList();
  23. }
  24. }
  25. public void DelSaveResponseMethod(string fullName)
  26. {
  27. if (string.IsNullOrWhiteSpace(fullName)) return;
  28. lock (syncSaveResponseMethods)
  29. {
  30. saveResponseMethods.Remove(fullName);
  31. }
  32. }
  33. public bool SaveResponseMethodEnable(string fullName)
  34. {
  35. return GrpcExtensionsOptions.Instance.GlobalSaveResponseEnable || (!string.IsNullOrWhiteSpace(fullName) && saveResponseMethods.Contains(fullName));
  36. }
  37. #endregion
  38. }
  39. }