Beispiel #1
0
        public static LogCastOptions Parse(string endpoint, string throttling, string retryTimeout,
                                           string sendingThreadCount, string sendTimeout, string enableSelfDiagnostics)
        {
            var options = new LogCastOptions(endpoint);

            if (!string.IsNullOrWhiteSpace(throttling))
            {
                options.Throttling = int.Parse(throttling);
            }
            if (!string.IsNullOrWhiteSpace(retryTimeout))
            {
                options.RetryTimeout = TimeSpan.Parse(retryTimeout);
            }
            if (!string.IsNullOrWhiteSpace(sendingThreadCount))
            {
                options.SendingThreadCount = int.Parse(sendingThreadCount);
            }
            if (!string.IsNullOrWhiteSpace(sendTimeout))
            {
                options.SendTimeout = TimeSpan.Parse(sendTimeout);
            }
            if (!string.IsNullOrWhiteSpace(enableSelfDiagnostics))
            {
                options.EnableSelfDiagnostics = ToBool(enableSelfDiagnostics);
            }

            return(options);
        }
Beispiel #2
0
        public LogCastClient([NotNull] LogCastOptions options, [NotNull] IFallbackLogger fallbackLogger)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (fallbackLogger == null)
            {
                throw new ArgumentNullException(nameof(fallbackLogger));
            }

            if (options.Endpoint == null)
            {
                fallbackLogger.Write("Endpoint cannot be null reference");
                throw new ArgumentException("Endpoint can not be null reference", nameof(options));
            }
            if (options.Throttling < 10)
            {
                fallbackLogger.Write("Throttling cannot be less than 10");
                throw new ArgumentException("Throttling can not be less than 10", nameof(options));
            }

            _options        = options;
            _fallbackLogger = fallbackLogger;
            _queue          = new BlockingCollection <LogCastMessageFactory>();

            var sendingThreadCount = _options.SendingThreadCount;
            var threadCount        = sendingThreadCount > 0 ? sendingThreadCount : 4;

            _countEvent = new CountEvent();
            Threads     = Enumerable
                          .Range(0, threadCount)
                          .Select(i => new Thread(Sender)
            {
                IsBackground = true
            })
                          .ToArray();

            foreach (var thread in Threads)
            {
                thread.Start();
            }
        }
Beispiel #3
0
 public ILogCastClient Create(LogCastOptions options, IFallbackLogger logger)
 {
     return(new LogCastClient(options, logger));
 }