public async Task <IActionResult> GetAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "todo/{id}")] HttpRequest req, int id, ILogger log) { using (log.BeginScope(new Dictionary <string, object>() { [Constants.FunctionName] = "GetToDo", ["Outer"] = "Outer", })) { log.LogInformation(EventConstants.GetTodoEventId, $"Fetching to do {{{Constants.TodoItemId}}}", id); using (log.BeginScope(new Dictionary <string, object>() { [Constants.CorrelationIdHeader] = correlationProvider.GetCorrelationId(), ["Inner"] = "Inner", })) { log.LogInformation(EventConstants.GetTodoEventId, $"This should have both CorrelationIdHeader and function name Fetching to do {{{Constants.TodoItemId}}}", id); var todoItem = await toDoItemsService.GetToDoItem(id); return(new OkObjectResult(todoItem)); } } }
public virtual async Task InvokeAsync(HttpContext context, RequestDelegate next) { _logger.Here(l => l.Entering(_correlationProvider, CorrelationIdHeaderName, _obtainCorrelationIdFromRequestHeaders)); if (_obtainCorrelationIdFromRequestHeaders) { string lowerCaseCorrelationIdHeaderName = CorrelationIdHeaderName.ToLower(); Microsoft.Extensions.Primitives.StringValues headerValue = context.Request.Headers.FirstOrDefault(x => x.Key.ToLower() == lowerCaseCorrelationIdHeaderName).Value; if (headerValue.Count > 0) { var correlationValue = headerValue.First(); _logger.Here(l => l.LogTrace("Using {@0} header value {@1} as correlation id.", CorrelationIdHeaderName, correlationValue)); _correlationProvider.SetCorrelationId(correlationValue); } } CorrelationProvider.CurrentCorrelationProvider = _correlationProvider; using (_logger.BeginScope(new[] { new KeyValuePair <string, object>(Constants.CorrelationId, _correlationProvider.GetCorrelationId()) })) { await next(context); } _logger.Here(l => l.Exiting()); }