/// <summary>
        /// Logs a statistics.
        /// </summary>
        /// <param name="logName">The name of the target log.</param>
        /// <param name="level">The log level used for logging the statistics</param>
        /// <param name="recursive">Bool telling if the log should be recursive, or just display averages.</param>
        /// <param name="statistics">The statistics to be logged</param>
        public static void Log(string logName, LogLevel level, bool recursive, StatisticsSet statistics)
        {
            Platform.Log(logName, level, GetLogString(statistics, recursive));

            foreach (IStatisticsLoggerListener extension in _extensions)
                extension.OnStatisticsLogged(statistics);
        }
        private static string GetLogString(StatisticsSet statistics, bool recursive)
        {
            XmlElement el = statistics.GetXmlElement(_doc, recursive);

            using (var sw = new StringWriter())
            {
                var settings = new XmlWriterSettings
                {
                    Indent = true,
                    NewLineOnAttributes = false,
                    OmitXmlDeclaration = true,
                    Encoding = Encoding.UTF8
                };

                using (XmlWriter writer = XmlWriter.Create(sw, settings))
                {
                    el.WriteTo(writer);
                    writer.Flush();

                    return sw.ToString();
                }
            }
        }
 /// <summary>
 /// Logs a statistics.
 /// </summary>
 /// <param name="logName">The name of the target log.</param>
 /// <param name="level">The log level used for logging the statistics</param>
 /// <param name="statistics">The statistics to be logged</param>
 public static void Log(string logName, LogLevel level, StatisticsSet statistics)
 {
     Log(logName, level, true, statistics);
 }
 /// <summary>
 /// Logs a statistics.
 /// </summary>
 /// <param name="level">The log level used for logging the statistics</param>
 /// <param name="statistics">The statistics to be logged</param>
 public static void Log(LogLevel level, StatisticsSet statistics)
 {
     Log(level, true, statistics);
 }
        protected virtual void ComputeAverage(StatisticsSet statistics)
        {
            foreach (IStatistics field in statistics.Fields)
            {
                IAverageStatistics average = field.NewAverageStatistics();

                if (average == null)
                    continue;

                object key = StatisticsHelper.ResolveID(average);
                if (this[key] != null)
                {
                    average = this[key] as IAverageStatistics;
                    Debug.Assert(average != null);
                }
                else
                {
                    AddField(average);
                }

                if (field is Statistics<int>)
                {
                    average.AddSample(((Statistics<int>) field).Value);
                }
                else if (field is Statistics<uint>)
                {
                    average.AddSample(((Statistics<uint>) field).Value);
                }
                else if (field is Statistics<long>)
                {
                    //sum += ((Statistics<long>)field).Value;
                    average.AddSample(((Statistics<long>) field).Value);
                }
                else if (field is Statistics<ulong>)
                {
                    average.AddSample(((Statistics<ulong>) field).Value);
                }
                else if (field is Statistics<double>)
                {
                    average.AddSample(((Statistics<double>) field).Value);
                }
                else if (field is TimeSpanStatistics)
                {
                    TimeSpanStatistics stat = field as TimeSpanStatistics;
                    if (stat.IsSet)
                        average.AddSample(((TimeSpanStatistics) field).Value);
                }
            }
        }
 /// <summary>
 /// Adds a sub-statistics.
 /// </summary>
 /// <param name="stat"></param>
 public void AddSubStats(StatisticsSet stat)
 {
     Debug.Assert(stat.Context != null);
     Platform.CheckForNullReference(stat, "stat");
     _subStatistics.Add(stat);
 }