private void EvaluateInternal( [NotNull] TextWriter writer, [NotNull] IReadOnlyDictionary <string, object> variables, CancellationToken cancellationToken) { Debug.Assert(writer != null, "Argument writer cannot be null."); Debug.Assert(variables != null, "Argument variables cannot be null."); /* Create a standard evaluation context that will be used for evaluation of said template. */ var context = new EvaluationContext( true, cancellationToken, Dialect.IdentifierComparer, Dialect.ObjectFormatter, Dialect.Self, Dialect.DecorateUnParsedText); /* Load in the variables. */ foreach (var variable in variables) { context.SetProperty(variable.Key, variable.Value); } /* Evaluate. */ _compiledTemplate.Evaluate(writer, context); }
protected static string Evaluate(CompiledTemplate <EvaluationContext> compiledTemplate, StringComparer comparer, params KeyValuePair <string, object>[] values) { var context = CreateContext(comparer); foreach (var kvp in values) { context.SetProperty(kvp.Key, kvp.Value); } string result; using (var sw = new StringWriter()) { compiledTemplate.Evaluate(sw, context); result = sw.ToString(); } return(result); }
/// <inheritdoc /> public void Format(LogEvent logEvent, TextWriter output) { _compiled.Evaluate(logEvent, output, _formatProvider); }