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.

63 lines
1.5 KiB

  1. using Apewer;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Threading;
  6. namespace Apewer.Internals
  7. {
  8. internal sealed class LogProvider
  9. {
  10. private static bool _running = false;
  11. private static Thread _thread = null;
  12. private static Queue<LogItem> _queue = new Queue<LogItem>();
  13. private static void Listener()
  14. {
  15. while (_running)
  16. {
  17. var item = (LogItem)null;
  18. lock (_queue)
  19. {
  20. if (_queue.Count > 0) item = _queue.Dequeue();
  21. else
  22. {
  23. _running = false;
  24. break;
  25. }
  26. }
  27. if (item == null) continue;
  28. if (item.Logger == null) continue;
  29. try
  30. {
  31. // item.Logger.Raise(item);
  32. }
  33. catch { }
  34. }
  35. }
  36. public static void Queue(LogItem argItem)
  37. {
  38. if (argItem == null) return;
  39. lock (_queue)
  40. {
  41. _queue.Enqueue(argItem);
  42. if (_thread == null)
  43. {
  44. _thread = new Thread(Listener);
  45. _thread.IsBackground = false;
  46. }
  47. if (!_running)
  48. {
  49. _running = true;
  50. _thread.Start();
  51. }
  52. }
  53. }
  54. }
  55. }