public void MultipleValueLogEventsIncludesProperties() { using (TestCorrelator.CreateContext()) { var options = new SerilogMetricsReporterOptions { LogEventLevel = LogEventLevel.Verbose }; var writer = new SerilogMetricSnapshotWriter(options); var columns = new [] { "A", "B", "C" }; var values = new object[] { 1, 2, 3 }; var metricTags = MetricTags.FromSetItemString("foo:10,bar:20"); writer.Write("context", "name", columns, values, metricTags, DateTime.UtcNow); var tagsProperty = metricTags.Keys.Zip(metricTags.Values, (key, value) => new KeyValuePair <ScalarValue, LogEventPropertyValue>( new ScalarValue(key), new ScalarValue(value))); var properties = new Dictionary <string, LogEventPropertyValue>() { { "context", new ScalarValue("context") }, { "name", new ScalarValue("name") }, { "A", new ScalarValue(1) }, { "B", new ScalarValue(2) }, { "C", new ScalarValue(3) }, { "tags", new DictionaryValue(tagsProperty) } }; TestCorrelator.GetLogEventsFromCurrentContext() .Should().ContainSingle() .Which.Properties.Should().BeEquivalentTo(properties); } }
public void SingleValueLogEventsAreWrittenAtSpecifiedLevel(LogEventLevel logEventLevel) { using (TestCorrelator.CreateContext()) { var options = new SerilogMetricsReporterOptions { LogEventLevel = logEventLevel }; var writer = new SerilogMetricSnapshotWriter(options); writer.Write("context", "name", 123, MetricTags.Empty, DateTime.UtcNow); TestCorrelator.GetLogEventsFromCurrentContext() .Should().ContainSingle() .Which.Level.Should().Be(logEventLevel); } }
public void SingleValueLogEventsAreWrittenAtSpecifiedTime() { using (TestCorrelator.CreateContext()) { var options = new SerilogMetricsReporterOptions { LogEventLevel = LogEventLevel.Verbose }; var writer = new SerilogMetricSnapshotWriter(options); var timestamp = DateTime.UtcNow; writer.Write("context", "name", "value", 123, MetricTags.Empty, timestamp); TestCorrelator.GetLogEventsFromCurrentContext() .Should().ContainSingle() .Which.Timestamp.Should().Be(timestamp); } }
public void SingleValueLogEventsUseMessageTemplate() { using (TestCorrelator.CreateContext()) { var options = new SerilogMetricsReporterOptions { LogEventLevel = LogEventLevel.Verbose, MessageTemplates = { Fallback = "Metric {name} in context {context}" } }; var writer = new SerilogMetricSnapshotWriter(options); var timestamp = DateTime.UtcNow; writer.Write("context", "name", 123, MetricTags.Empty, timestamp); TestCorrelator.GetLogEventsFromCurrentContext() .Should().ContainSingle() .Which.RenderMessage().Should().Be("Metric \"name\" in context \"context\""); } }
public void MultipleValueLogEventsUseMessageTemplate() { using (TestCorrelator.CreateContext()) { var options = new SerilogMetricsReporterOptions { LogEventLevel = LogEventLevel.Verbose, MessageTemplates = { Fallback = "Metric {name} in context {context}" } }; var writer = new SerilogMetricSnapshotWriter(options); var columns = new [] { "A", "B", "C" }; var values = new object[] { 1, 2, 3 }; writer.Write("context", "name", columns, values, MetricTags.Empty, DateTime.UtcNow); TestCorrelator.GetLogEventsFromCurrentContext() .Should().ContainSingle() .Which.RenderMessage().Should().Be("Metric \"name\" in context \"context\""); } }