Guest User

Untitled

a guest
Dec 11th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. // using
  2. // private LoggerEx _logger = new LoggerEx(Logger, TimeSpan.FromSeconds(5));
  3. //_logger.Log(
  4. // () => $"media state: {this._vlcControl?.Media?.State}",
  5. // () => $"media player state: {this._vlcControl?.State}",
  6. // () =>
  7. // {
  8. // var stats = this._vlcControl?.Media?.Statistics;
  9. // return $@"ReadBytes: {stats?.ReadBytes},
  10. // InputBitrate: {stats?.InputBitrate},
  11. // DemuxReadBytes: {stats?.DemuxReadBytes},
  12. // DemuxCorrupted: {stats?.DemuxCorrupted},
  13. // DemuxDiscontinuity: {stats?.DemuxDiscontinuity},
  14. // DecodedVideo: {stats?.DecodedVideo},
  15. // DecodedAudio: {stats?.DecodedAudio},
  16. // DisplayedPictures: {stats?.DisplayedPictures},
  17. // LostPictures: {stats?.LostPictures},
  18. // PlayedAusioBuffers: {stats?.PlayedAusioBuffers}
  19. // LostAudioBuffers: {stats?.LostAudioBuffers},
  20. // SentPackets: {stats?.SentPackets},
  21. // SentBytes: {stats?.SentBytes},
  22. // SendBitrate: {stats?.SendBitrate}";
  23. // },
  24. // () => $"errorMessage: {VlcContext.ErrorHandling.GetErrorMessage()}",
  25. // () => $"FPS: {this._vlcControl?.FPS}",
  26. // () => $"Position: {this._vlcControl?.Position}",
  27. // () => $"Rate: {this._vlcControl?.Rate}");
  28.  
  29. public class LoggerEx
  30. {
  31. private Logger logger;
  32. private readonly TimeSpan _logDuration;
  33. private DateTime _lastLogTime;
  34.  
  35. public LoggerEx(Logger logger, TimeSpan logDuration)
  36. {
  37. this.logger = logger;
  38. _logDuration = logDuration;
  39. _lastLogTime = DateTime.Now;
  40. }
  41.  
  42. public void Log(params Func<string>[] logActions)
  43. {
  44. if (DateTime.Now - _lastLogTime >= _logDuration)
  45. {
  46. var sb = new StringBuilder();
  47. foreach (var logAction in logActions)
  48. {
  49. try
  50. {
  51. var message = logAction?.Invoke();
  52. if (!string.IsNullOrEmpty(message))
  53. {
  54. sb.AppendLine(message);
  55. }
  56. }
  57. catch (Exception e)
  58. {
  59.  
  60. }
  61. }
  62.  
  63. logger.Info(sb.ToString());
  64.  
  65. _lastLogTime = DateTime.Now;
  66. }
  67. }
  68. }
Add Comment
Please, Sign In to add comment