Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // using
- // private LoggerEx _logger = new LoggerEx(Logger, TimeSpan.FromSeconds(5));
- //_logger.Log(
- // () => $"media state: {this._vlcControl?.Media?.State}",
- // () => $"media player state: {this._vlcControl?.State}",
- // () =>
- // {
- // var stats = this._vlcControl?.Media?.Statistics;
- // return $@"ReadBytes: {stats?.ReadBytes},
- // InputBitrate: {stats?.InputBitrate},
- // DemuxReadBytes: {stats?.DemuxReadBytes},
- // DemuxCorrupted: {stats?.DemuxCorrupted},
- // DemuxDiscontinuity: {stats?.DemuxDiscontinuity},
- // DecodedVideo: {stats?.DecodedVideo},
- // DecodedAudio: {stats?.DecodedAudio},
- // DisplayedPictures: {stats?.DisplayedPictures},
- // LostPictures: {stats?.LostPictures},
- // PlayedAusioBuffers: {stats?.PlayedAusioBuffers}
- // LostAudioBuffers: {stats?.LostAudioBuffers},
- // SentPackets: {stats?.SentPackets},
- // SentBytes: {stats?.SentBytes},
- // SendBitrate: {stats?.SendBitrate}";
- // },
- // () => $"errorMessage: {VlcContext.ErrorHandling.GetErrorMessage()}",
- // () => $"FPS: {this._vlcControl?.FPS}",
- // () => $"Position: {this._vlcControl?.Position}",
- // () => $"Rate: {this._vlcControl?.Rate}");
- public class LoggerEx
- {
- private Logger logger;
- private readonly TimeSpan _logDuration;
- private DateTime _lastLogTime;
- public LoggerEx(Logger logger, TimeSpan logDuration)
- {
- this.logger = logger;
- _logDuration = logDuration;
- _lastLogTime = DateTime.Now;
- }
- public void Log(params Func<string>[] logActions)
- {
- if (DateTime.Now - _lastLogTime >= _logDuration)
- {
- var sb = new StringBuilder();
- foreach (var logAction in logActions)
- {
- try
- {
- var message = logAction?.Invoke();
- if (!string.IsNullOrEmpty(message))
- {
- sb.AppendLine(message);
- }
- }
- catch (Exception e)
- {
- }
- }
- logger.Info(sb.ToString());
- _lastLogTime = DateTime.Now;
- }
- }
- }
Add Comment
Please, Sign In to add comment