/// <summary> /// Format the log event into the output. /// </summary> /// <param name="logEvent">The event to format.</param> /// <param name="output">The output.</param> public void Format(LogEvent logEvent, TextWriter output) { if (logEvent == null) { throw new ArgumentNullException("logEvent"); } if (output == null) { throw new ArgumentNullException("output"); } // This could be lazier: the output properties include // everything from the log event, but often we won't need any more than // just the standard timestamp/message etc. var outputProperties = OutputProperties.GetOutputProperties(logEvent); foreach (var token in _outputTemplate.Tokens) { var pt = token as PropertyToken; if (pt == null) { token.Render(outputProperties, output, _formatProvider); continue; } // First variation from normal rendering - if a property is missing, // don't render anything (message templates render the raw token here). LogEventPropertyValue propertyValue; if (!outputProperties.TryGetValue(pt.PropertyName, out propertyValue)) { continue; } // Second variation; if the value is a scalar string, use literal // rendering and support some additional formats: 'u' for uppercase // and 'w' for lowercase. var sv = propertyValue as ScalarValue; if (sv != null && sv.Value is string) { var overridden = new Dictionary <string, LogEventPropertyValue> { { pt.PropertyName, new LiteralStringValue((string)sv.Value) } }; token.Render(overridden, output, _formatProvider); } else { token.Render(outputProperties, output, _formatProvider); } } }
/// <summary> /// Format the log event into the output. /// </summary> /// <param name="logEvent">The event to format.</param> /// <param name="output">The output.</param> public void Format(LogEvent logEvent, TextWriter output) { if (logEvent == null) { throw new ArgumentNullException("logEvent"); } if (output == null) { throw new ArgumentNullException("output"); } var outputProperties = OutputProperties.GetOutputProperties(logEvent); _outputTemplate.Render(outputProperties, output, _formatProvider); }