public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, Route = "kubernetes/events/forward")] HttpRequest request) { var payload = await request.ReadAsStringAsync(); _logger.LogInformation($"Kubernetes event received: {payload}"); var cloudEvent = _cloudEventFactory.CreateFromRawKubernetesEvent(payload); await _eventGridPublisher.PublishAsync(cloudEvent); ILoggerExtensions.LogMetric(_logger, "Kubernetes Event Published", 1); }
public void WithCorrelationIdWithMissingCorrelationId(string correlationId) { var logger = new Mock <ILogger>(); ILoggerExtensions.WithCorrelationId(logger.Object, correlationId).Should().BeSameAs(logger.Object, "because the logger instance should be returned"); logger.Verify(instance => instance.ForContext(It.Is <string>(property => property == LogPropertyNames.CorrelationId), It.Is <string>(id => id == correlationId), It.IsAny <bool>()), Times.Never, "because the correlation identifier was missing"); }
public void WithCorrelationIdWithValidCorrelationId() { var correlationId = "ABC123"; var logger = new Mock <ILogger>(); ILoggerExtensions.WithCorrelationId(logger.Object, correlationId); logger.Verify(instance => instance.ForContext(It.Is <string>(property => property == LogPropertyNames.CorrelationId), It.Is <string>(id => id == correlationId), It.IsAny <bool>()), Times.Once, "because the correlation identifier was provided"); }
private static void SetupAndExecute(bool shouldLog, Action <TestLogger> testOp) { var logger = new TestLogger(); var mockSettings = new Mock <IEnvironmentSettings>(); mockSettings.Setup(x => x.ShouldLogDebugMessages()).Returns(shouldLog); try { ILoggerExtensions.Initialize(mockSettings.Object); // Act testOp(logger); } finally { // Re-initialize from whatever the real environment settings are ILoggerExtensions.Initialize(new EnvironmentSettings()); } }
public void WithCorrelationIdWithNullLogger() { ILoggerExtensions.WithCorrelationId(null, "blue").Should().BeNull("because the logger was null"); }