Example #1
0
        internal void LogMetric(string metricName, string value, string metricType, string postfix = "")
        {
            if (!_provider.IsConnected && _provider.Connect())
            {
                options.LogEvent("unable to connect message transport", EventType.Error);
                return;
            }
            var calculateMetric = BuildMetric(metricName, value, metricType, options.Prefix, postfix);

            options.LogEvent(calculateMetric, EventType.Info);
            if (string.IsNullOrWhiteSpace(calculateMetric))
            {
                options.LogEvent($"Unable to generate metric for {metricType} value {value}", EventType.Error);
            }
            try
            {
                _provider.SendMetric(calculateMetric);
            }
            catch (Exception e)
            {
                options?.LogException(e);
            }
        }
Example #2
0
 /// <summary>
 /// Create a statsd client
 /// </summary>
 /// <param name="options">client options </param>
 /// <param name="provider">provider, defaults to udp if none is passed</param>
 public Statsd(StatsdOptions options, BaseCommunicationProvider provider = null)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     if (provider == null)
     {
         provider = new Udp();
     }
     if (string.IsNullOrEmpty(options.HostOrIp))
     {
         options.LogEvent("No host or ip provided, failing back to null output", EventType.Error);
         _provider = new NullChannel();
     }
     if (options.Port < 0)
     {
         options.LogEvent("port provided, failing back to null output", EventType.Error);
         _provider = new NullChannel();
     }
     this.options = options;
     _provider    = provider.Construct(options);
 }