public void WhenCreateException_ThenBuildShoulNotThrow() { var options = new GraylogSinkOptions(); ExceptionMessageBuilder exceptionBuilder = new ExceptionMessageBuilder("localhost", options); Exception testExc = null; try { try { throw new InvalidOperationException("Level One exception"); } catch (Exception exc) { throw new NotImplementedException("Nested Exception", exc); } } catch (Exception exc) { testExc = exc; } DateTimeOffset date = DateTimeOffset.Now; LogEvent logEvent = LogEventSource.GetExceptionLogEvent(date, testExc); JObject obj = exceptionBuilder.Build(logEvent); obj.Should().NotBeNull(); }
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); }
static void Main(string[] args) { using (EventLogListener listener = new EventLogListener()) { LogEventSource eventSource = new LogEventSource(); eventSource.SampleLogFunction(); } }
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); }
public void WhenLogErrorEvent_ThenErrorMessageBuilderShouldBeCalled() { var errorBuilder = new Mock <IMessageBuilder>(); var messageBuilder = new Mock <IMessageBuilder>(); var messageBuilders = new Dictionary <BuilderType, Lazy <IMessageBuilder> > { [BuilderType.Exception] = new Lazy <IMessageBuilder>(() => errorBuilder.Object), [BuilderType.Message] = new Lazy <IMessageBuilder>(() => messageBuilder.Object) }; GelfConverter target = new GelfConverter(messageBuilders); var simpleEvent = LogEventSource.GetErrorEvent(DateTimeOffset.Now); target.GetGelfJson(simpleEvent); errorBuilder.Verify(c => c.Build(simpleEvent), Times.Once); messageBuilder.Verify(c => c.Build(simpleEvent), Times.Never); }