本文整理汇总了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)));
}
}