public async Task DetectAndBlurFaces( [EventGridTrigger] EventGridEvent eventGridEvent, ILogger logger ) { CustomEventData inputEventData = ((JObject)eventGridEvent.Data).ToObject <CustomEventData>(); var correlationId = LoggingHelper.GetCorrelationId(inputEventData); #region Logging logger.LogInformation( new EventId((int)LoggingConstants.EventId.DetectAndBlurFacesStarted), LoggingConstants.Template, LoggingConstants.EventId.DetectAndBlurFacesStarted.ToString(), correlationId, LoggingConstants.ProcessingFunction.DetectAndBlurFaces.ToString(), LoggingConstants.ProcessStatus.Started, "Execution Started" ); #endregion CustomEventData outputEventData = new CustomEventData { ImageUrl = inputEventData.ImageUrl, TicketNumber = inputEventData.TicketNumber, DistrictOfInfraction = inputEventData.DistrictOfInfraction, DateOfInfraction = inputEventData.DateOfInfraction }; try { var detectedFaces = await _faceHandler .DetectFacesWithUrlAsync(inputEventData.ImageUrl) .ConfigureAwait(false); var imageBytes = await _blobHandler .DownloadBlobAsync(inputEventData.ImageUrl) .ConfigureAwait(false); var blurredImageBytes = await _faceHandler .BlurFacesAsync(imageBytes, detectedFaces.ToList()); using (MemoryStream ms = new MemoryStream(blurredImageBytes)) { await _blobHandler.UploadStreamAsBlobAsync( containerName : _options.BlurredImageContainerName, stream : ms, contentType : _options.UploadContentType, blobName : BlobHelper.GetBlobNameWithExtension(inputEventData.TicketNumber) ) .ConfigureAwait(false); } outputEventData.CustomEvent = CustomEvent.FaceDetectionAndBlurringCompleted.ToString(); #region Logging logger.LogInformation( new EventId((int)LoggingConstants.EventId.DetectAndBlurFacesFinished), LoggingConstants.Template, LoggingConstants.EventId.DetectAndBlurFacesFinished.ToString(), correlationId, LoggingConstants.ProcessingFunction.DetectAndBlurFaces.ToString(), LoggingConstants.ProcessStatus.Finished, "Execution Finished" ); #endregion } catch (Exception ex) { outputEventData.CustomEvent = CustomEvent.Exceptioned.ToString(); #region Logging logger.LogInformation( new EventId((int)LoggingConstants.EventId.DetectAndBlurFacesFinished), LoggingConstants.Template, LoggingConstants.EventId.DetectAndBlurFacesFinished.ToString(), correlationId, LoggingConstants.ProcessingFunction.DetectAndBlurFaces.ToString(), LoggingConstants.ProcessStatus.Failed, $"Execution Failed. Reason: {ex.Message}" ); #endregion } await _eventhandler.PublishEventToTopicAsync(outputEventData) .ConfigureAwait(false); }