コード例 #1
0
        /// <summary>
        /// Generates XML representing the given metrics properties.
        /// </summary>
        /// <param name="metrics">
        /// The metrics properties. 
        /// </param>
        /// <returns>
        /// An XML metrics element. 
        /// </returns>
        private static XElement GenerateMetricsXml(MetricsProperties metrics)
        {
            if (!Enum.IsDefined(typeof(MetricsLevel), metrics.MetricsLevel))
            {
                throw new InvalidOperationException("Invalid metrics level specified.");
            }

            if (string.IsNullOrEmpty(metrics.Version))
            {
                throw new InvalidOperationException("The metrics version is null or empty.");
            }

            var enabled = metrics.MetricsLevel != MetricsLevel.None;

            var xml = new XElement(
                MetricsName,
                new XElement(VersionName, metrics.Version),
                new XElement(EnabledName, enabled),
                GenerateRetentionPolicyXml(metrics.RetentionDays));

            if (enabled)
            {
                xml.Add(new XElement(IncludeApisName, metrics.MetricsLevel == MetricsLevel.ServiceAndApi));
            }

            return xml;
        }