public void LowercaseFormatSpecifierIsSupportedForStrings() { var formatter = new MessageTemplateTextFormatter("{Name:w}", CultureInfo.InvariantCulture); var evt = DelegatingSink.GetLogEvent(l => l.Information("{Name}", "Nick")); var sw = new StringWriter(); formatter.Format(evt, sw); Assert.AreEqual("nick", sw.ToString()); }
public void MessageTemplatesContainingFormatStringPropertiesRenderCorrectly() { var formatter = new MessageTemplateTextFormatter("{Message:l}", CultureInfo.InvariantCulture); var evt = DelegatingSink.GetLogEvent(l => l.Information("{Message}", "Hello, world!")); var sw = new StringWriter(); formatter.Format(evt, sw); Assert.AreEqual("\"Hello, world!\"", sw.ToString()); }
public void DefaultLevelLengthIsFullText() { var formatter = new MessageTemplateTextFormatter("{Level}", CultureInfo.InvariantCulture); var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello")); var sw = new StringWriter(); formatter.Format(evt, sw); Assert.Equal("Information", sw.ToString()); }
public void AppliesCustomFormatterToEnums() { var formatter = new MessageTemplateTextFormatter("{Message}", new SizeFormatter(CultureInfo.InvariantCulture)); var evt = DelegatingSink.GetLogEvent(l => l.Information("Size {Size}", Size.Large)); var sw = new StringWriter(); formatter.Format(evt, sw); Assert.Equal("Size Huge", sw.ToString()); }
public void AligmentAndWidthCanBeCombined() { var formatter = new MessageTemplateTextFormatter("{Level,5:w3}", CultureInfo.InvariantCulture); var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello")); var sw = new StringWriter(); formatter.Format(evt, sw); Assert.Equal(" inf", sw.ToString()); }
public void UsesFormatProvider() { var french = CultureInfo.GetCultureInfo("fr-FR"); var formatter = new MessageTemplateTextFormatter("{Message:l}", french); var evt = DelegatingSink.GetLogEvent(l => l.Information("{0}", 12.345)); var sw = new StringWriter(); formatter.Format(evt, sw); Assert.AreEqual("12,345", sw.ToString()); }
public void FixedLengthLevelSupportsUpperCasing() { var formatter = new MessageTemplateTextFormatter("{Level:u3}", CultureInfo.InvariantCulture); var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello")); var sw = new StringWriter(); formatter.Format(evt, sw); Assert.Equal("INF", sw.ToString()); }
public void FixedLengthLevelIsSupported( LogEventLevel level, int width, string expected) { var formatter = new MessageTemplateTextFormatter($"{{Level:t{width}}}", CultureInfo.InvariantCulture); var evt = DelegatingSink.GetLogEvent(l => l.Write(level, "Hello")); var sw = new StringWriter(); formatter.Format(evt, sw); Assert.Equal(expected, sw.ToString()); }