public bool ValidateTemplated(Templating.StructuredMessage message, string tag) { foreach (var filter in TemplatedFilters) { if (!filter.Validate(message, tag)) { return(false); } } return(true); }
/// <summary> /// Parses a template and its property values and returns the resulting message. /// </summary> /// <param name="template">The template.</param> /// <param name="templateSource">The source of the template.</param> /// <param name="values">An array of values to resolve for the template's propeties.</param> public static StructuredMessage BuildMessage(Template template, string templateSource, params object[] values) { Dictionary <string, int> indices = new Dictionary <string, int>(); int valuesIndex = 0; StructuredMessage message = new StructuredMessage(templateSource, template); var tokens = template.GetTokens(); for (var i = 0; i < tokens.Length; i++) { var token = tokens[i]; if (token is PropertyHoleToken propertyToken) { if (!indices.ContainsKey(propertyToken.PropertyName)) { if (valuesIndex >= values.Length) { continue; } indices.Add(propertyToken.PropertyName, valuesIndex); message.TemplateValues.Add(i, new PropertyValue(values[valuesIndex], propertyToken.GetModifier())); valuesIndex++; } else { var valueIndex = indices[propertyToken.PropertyName]; if (valueIndex >= values.Length) { continue; } message.TemplateValues.Add(i, new PropertyValue(values[valueIndex], propertyToken.GetModifier())); } } } return(message); }
public override void ProcessMessage(StructuredMessage message, string tag) { Log.WriteTag(TemplateProcessor.BuildString(message), tag); }