예제 #1
0
        /// <summary>
        /// Write the current round of stats to the log
        /// </summary>
        /// <param name="log">The logger to write to</param>
        public void WriteStatsToFile(ILogger log)
        {
            try {
                var statsContainer = new StatsContainer();
                statsContainer.Add(GetStats());
                var rawStats = statsContainer.GetStats(useGrouping: false, useMetadata: false);
                if (!_csv)
                {
                    rawStats.Add("timestamp", DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture));
                    log.Information("{@stats}", rawStats);
                }
                else
                {
                    var writeHeader = false;
                    var header      = StatsCsvEncoder.GetHeader(rawStats);
                    if (header != _lastWrittenCsvHeader)
                    {
                        _lastWrittenCsvHeader = header;
                        writeHeader           = true;
                    }

                    var line      = StatsCsvEncoder.GetLine(rawStats);
                    var timestamp = GetTimestamp(line);

                    if (writeHeader)
                    {
                        log.Information(Environment.NewLine);
                        log.Information(header);
                    }
                    log.Information(line);
                }
            } catch (Exception ex) {
                Log.Error(ex, "Error on regular stats collection.");
            }
        }
예제 #2
0
        private void CollectRegularStats()
        {
            try
            {
                var stats = GetStats();
                if (stats != null)
                {
                    var rawStats = stats.GetRawStats();

                    var header = StatsCsvEncoder.GetHeader(rawStats);
                    if (header != _lastWrittenCsvHeader)
                    {
                        _lastWrittenCsvHeader = header;
                        RegularLog.Info(Environment.NewLine);
                        RegularLog.Info(header);
                    }

                    var line = StatsCsvEncoder.GetLine(rawStats);
                    RegularLog.Info(line);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorException(ex, "error on regular stats collection");
            }
        }
        private void SaveStatsToCsvFile(Dictionary <string, object> rawStats)
        {
            var header = StatsCsvEncoder.GetHeader(rawStats);

            if (header != _lastWrittenCsvHeader)
            {
                _lastWrittenCsvHeader = header;
                RegularLog.Info(Environment.NewLine);
                RegularLog.Info(header);
            }

            var line = StatsCsvEncoder.GetLine(rawStats);

            RegularLog.Info(line);
        }
예제 #4
0
        private void SaveStatsToFile(Dictionary <string, object> rawStats)
        {
            if (LogManager.StructuredLog)
            {
                RegularLog.Info("{@stats}", rawStats);
            }
            else
            {
                var header = StatsCsvEncoder.GetHeader(rawStats);
                if (header != _lastWrittenCsvHeader)
                {
                    _lastWrittenCsvHeader = header;
                    RegularLog.Info(Environment.NewLine);
                    RegularLog.Info(header);
                }

                var line = StatsCsvEncoder.GetLine(rawStats);
                RegularLog.Info(line);
            }
        }
        private void SaveStatsToFile(Dictionary <string, object> rawStats)
        {
            if (LogManager.StructuredLog)
            {
                rawStats.Add("timestamp", DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture));
                RegularLog.Info("{@stats}", rawStats);
            }
            else
            {
                var writeHeader = false;

                var header = StatsCsvEncoder.GetHeader(rawStats);
                if (header != _lastWrittenCsvHeader)
                {
                    _lastWrittenCsvHeader = header;
                    writeHeader           = true;
                }

                var line      = StatsCsvEncoder.GetLine(rawStats);
                var timestamp = GetTimestamp(line);
                if (timestamp.HasValue)
                {
                    if (timestamp.Value.Day != _lastCsvTimestamp.Day)
                    {
                        writeHeader = true;
                    }
                    _lastCsvTimestamp = timestamp.Value;
                }

                if (writeHeader)
                {
                    RegularLog.Info(Environment.NewLine);
                    RegularLog.Info(header);
                }
                RegularLog.Info(line);
            }
        }