当前位置: 首页>>代码示例>>C#>>正文


C# ILog.GetData方法代码示例

本文整理汇总了C#中ILog.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# ILog.GetData方法的具体用法?C# ILog.GetData怎么用?C# ILog.GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILog的用法示例。


在下文中一共展示了ILog.GetData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Map

        /// <summary>
        /// Attempts to map a dictionary using the LogMappings
        /// </summary>
        /// <param name="log">The log to map</param>
        /// <returns>A dictionary of mapped key value pairs</returns>
        public IEnumerable<IDictionary<string, object>> Map(ILog log)
        {
            if (LogMappingsRules.Any(l => l.Type == log.Type))
            {
                var data = log.GetData();
                foreach (var typePolicy in LogMappingsRules.Where(l => l.Type == log.Type))
                {
                    bool skipPolicy = false;
                    if (typePolicy.Conditions != null)
                    {
                        // filtering based on condition is also available, a log must have a param set to a specific value. This is used to exclude the Snapshot quality logs
                        foreach (var condition in typePolicy.Conditions)
                        {
                            if (!data.ContainsKey(condition.Key)) skipPolicy = true;
                            else
                            {
                                var serializedValue = LoggingExtensions.SerializeValue(data[condition.Key]);
                                if (condition.Value == "*")
                                {
                                    skipPolicy = string.IsNullOrEmpty(serializedValue);
                                }
                                else
                                {
                                    skipPolicy = serializedValue != condition.Value;
                                }
                            }
                            if (skipPolicy) break;
                        }
                    }

                    if (!skipPolicy)
                    {
                        bool errorOccurred = false;
                        var output = new Dictionary<string, object>();
                        foreach (var policy in typePolicy.Values)
                        {
                            if (data.ContainsKey(policy.OriginalKey))
                            {
                                object value = data[policy.OriginalKey];
                                if (value != null)
                                {
                                    if (policy.OriginalKey == LogAttributes.Type)
                                    {
                                        if (typePolicy.SerializedId != null)
                                            output.Add(policy.NewKey, typePolicy.SerializedId);
                                    }
                                    else
                                    {
                                        output.Add(policy.NewKey, value);
                                    }
                                }
                                else if (!policy.Optional)
                                {
                                    // policy not found for the log value
                                    OnMappingException(new Exception(string.Format("Log property '{0}' must be set.", policy.OriginalKey)));
                                    errorOccurred = true;
                                }
                            }
                            else
                            {
                                // policy not found for the log value
                                OnMappingException(new Exception(string.Format("Log property '{0}' not found.", policy.OriginalKey)));
                                errorOccurred = true;
                            }
                        }
                        if (errorOccurred)
                            output.Add("err", "1");

                        yield return output;
                    }
                }
            }
            else
            {
                // policy not found for the log type
                OnMappingException(new Exception(string.Format("Mapping Rule not found for log type '{0}'", log.Type)));
            }
        }
开发者ID:bondarenkod,项目名称:pf-arm-deploy-error,代码行数:83,代码来源:MappingPolicy.cs


注:本文中的ILog.GetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。