private void UpdateCounterFreshnessTime(LogEventArgs eventArgs)
        {
            if (!_settings.Aggregators.Any(a => a.CounterCategory == eventArgs.LogEvent.Category && a.CounterName ==  eventArgs.LogEvent.Counter))
                return;

            string counter = String.Format("{0}_{1}_{2}_{3}", eventArgs.LogEvent.Category, eventArgs.LogEvent.Counter,
                                           eventArgs.LogEvent.Source, eventArgs.LogEvent.Instance);
            _counterFreshnessTime.AddOrUpdate(counter, DateTime.Now, (key, existingValue) => DateTime.Now);
        }
 private void DumpCounters(LogEventArgs eventArgs)
 {
     FileStream df = GetDumpFile(eventArgs.LogEvent.Category, eventArgs.LogEvent.Counter,
                                 eventArgs.LogEvent.DateTime);
     byte[] toWrite = Encoding.Default.GetBytes(eventArgs.LogEvent.ToString()+"\r\n");
     lock (df)
     {
         df.Write(toWrite, 0, toWrite.Length);    
     }
 }
        private void DiscoverNewCounters(LogEventArgs eventArgs)
        {
            if (_knownCounters.Contains(eventArgs.LogEvent.Category + "\t" + eventArgs.LogEvent.Counter))
                return;

            lock (_lock)
            {
                if (_knownCounters.Contains(eventArgs.LogEvent.Category + "\t" + eventArgs.LogEvent.Counter))
                    return;

                File.AppendAllText(@"settings\AutoDiscoveredCounters.list",
                                   "\r\n" + eventArgs.LogEvent.Category + "\t" + eventArgs.LogEvent.Counter);
                DiscoverBasedOnGenericCounters(eventArgs);
                _knownCounters.Add(eventArgs.LogEvent.Category + "\t" + eventArgs.LogEvent.Counter);
            }
        }
 private void DiscoverBasedOnGenericCounters(LogEventArgs eventArgs)
 {
     int cnt = _settings.Aggregators.Count;
     for (int i = 0; i < cnt; i++)
     {
         CounterAggregator counterAggregator = _settings.Aggregators[i];
         if ((eventArgs.LogEvent.Category == counterAggregator.CounterCategory) &&
             (eventArgs.LogEvent.Counter.StartsWith(counterAggregator.CounterName)) &&
             (eventArgs.LogEvent.Counter.Length > counterAggregator.CounterName.Length))
         {
             CounterAggregator aggregator = new CounterAggregator(counterAggregator.CounterCategory,
                                                                  eventArgs.LogEvent.Counter,
                                                                  counterAggregator.AggregationType,
                                                                  counterAggregator.InputType,"");
             _settings.AddAggregator(aggregator);
             File.AppendAllText(@"settings\counters.list",
                                "\r\n" + aggregator.CounterCategory + "\t" + aggregator.CounterName + "\t" +
                                aggregator.AggregationType.ToString() + "\t" + aggregator.InputType.FullName);
         }
     }
 }
 private CounterGroup CreateCounterGroupByMask(string mask, LogEventArgs eventArgs)
 {
     if (mask.Length !=3) throw new Exception("Mask should be exactly 3 chars length");
     return new CounterGroup(
         eventArgs.LogEvent.Counter,
         mask[0] == '0' ? "ALL_SOURCES" : eventArgs.LogEvent.Source,
         mask[1] == '0' ? "ALL_INSTANCES" : eventArgs.LogEvent.Instance,
         mask[2] == '0' ? "ALL_EXTDATA" : eventArgs.LogEvent.ExtendedData
         );
 }
 private void Forward(LogEventArgs eventArgs)
 {
     if (_tcpClient == null)
     {
         SheduleReconnect();
         return;
     }
     byte[] data = eventArgs.LogEvent.Serialize();
     _tcpClientLocker.EnterReadLock();
     try
     {
         _tcpClient.Send(new MessagePacket(data).GetBytesForTransfer());
     }
     catch (Exception ex)
     {
         _logger.Error("Error while sending\r\n" + ex);
     }
     finally
     {
         _tcpClientLocker.ExitReadLock();
     }
 }
 private void InvokeOnLogEvent(LogEventArgs e)
 {
     string counterNameReplacement = Settings.ExtendedDataTransformations.GetCounterNameReplacement(e.LogEvent.ExtendedData);
     e.LogEvent.Counter += counterNameReplacement;
     _eventSubject.OnNext(e);
 }
 private void OnEventFromLog(object sender, LogEventArgs e)
 {
     var handler = EventFromLog;
     if (handler == null) return;
     handler(sender, e);
 }