public void WhenMessageBuilding_ShouldIgnorePropertyNames() { var sut = new GelfMessageBuilder("localhost", new GraylogSinkOptions { PropertyNamingStrategy = new NoOpPropertyNamingStrategy() }); var @event = new LogEvent(DateTimeOffset.Now, LogEventLevel.Information, null, new MessageTemplate("abcdef{TestProp}", new List <MessageTemplateToken> { new TextToken("abcdef", 0), new PropertyToken("LongPropertyName", "zxc", alignment: new Alignment(AlignmentDirection.Left, 3)), new PropertyToken("Short", "zxc", alignment: new Alignment(AlignmentDirection.Left, 3)) }), new List <LogEventProperty> { new LogEventProperty("LongPropertyName", new ScalarValue("zxc")), new LogEventProperty("Short", new ScalarValue("zxc")), new LogEventProperty("id", new ScalarValue("asd")) }); var actual = sut.Build(@event); Assert.Null(actual.Property("_longPropertyName")); Assert.Null(actual.Property("_short")); Assert.NotNull(actual.Property("_LongPropertyName")); Assert.NotNull(actual.Property("_Short")); }
public void WhenGetSimpleEvent_ThenResult_ShouldBeExpected() { var options = new GraylogSinkOptions(); var target = new GelfMessageBuilder("localhost", options); var date = DateTimeOffset.Now; var expected = new { facility = "GELF", full_message = "abcdef\"zxc\"", host = "localhost", level = 2, short_message = "abcdef\"zxc\"", timestamp = date.DateTime, version = "1.1", _stringLevel = "Information", _TestProp = "\"zxc\"", _id_ = "\"asd\"" }; LogEvent logEvent = LogEventSource.GetSimpleLogEvent(date); string expectedString = JsonConvert.SerializeObject(expected, Newtonsoft.Json.Formatting.None); string actual = target.Build(logEvent).ToString(Newtonsoft.Json.Formatting.None); //actual.ShouldBeEquivalentTo(expectedString); }
public void TryComplexEvent() { var options = new GraylogSinkOptions(); var target = new GelfMessageBuilder("localhost", options); DateTimeOffset date = DateTimeOffset.Now; LogEvent logEvent = LogEventSource.GetComplexEvent(date); string actual = target.Build(logEvent).ToString(Newtonsoft.Json.Formatting.None); }
public void GetSimpleLogEvent_GraylogSinkOptionsContainsHost_ReturnsOptionsHost() { //arrange GraylogSinkOptions options = new GraylogSinkOptions() { Host = "my_host" }; GelfMessageBuilder messageBuilder = new GelfMessageBuilder("localhost", options); DateTime date = DateTime.UtcNow; string expectedHost = "my_host"; //act LogEvent logEvent = LogEventSource.GetSimpleLogEvent(date); JObject actual = messageBuilder.Build(logEvent); string actualHost = actual.Value <string>("host"); //assert Assert.Equal(expectedHost, actualHost); }