private async Task EndPage()
        {
            if (pageWriter != null)
            {
                pageWriter.Flush();
                pageData.Flush();
                pageWriter.Dispose();
                pageWriter = null;
                pageData   = null;
                var log     = new TaskLog(string.Format(@"logs\{0:D}", taskProperties.TaskInstanceId));
                var taskLog = await taskClient.CreateLogAsync(log).ConfigureAwait(false);

                // Upload the contents
                using (var fs = File.Open(dataFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    await taskClient.AppendLogContentAsync(taskLog.Id, fs).ConfigureAwait(false);
                }

                // Create a new record and only set the Log field
                var attachmentUpdataRecord = new TimelineRecord {
                    Id = taskProperties.TaskInstanceId, Log = taskLog
                };
                await taskClient.UpdateTimelineRecordAsync(attachmentUpdataRecord, default(CancellationToken)).ConfigureAwait(false);
            }
        }
        public async Task CreateTaskTimelineRecordIfRequired(TaskClient taskClient, CancellationToken cancellationToken)
        {
            if (taskProperties.TaskInstanceId.Equals(Guid.Empty))
            {
                taskProperties.TaskInstanceId = Guid.NewGuid();
            }

            var timelineRecord = new TimelineRecord
            {
                Id         = taskProperties.TaskInstanceId,
                RecordType = "task",
                StartTime  = DateTime.UtcNow,
                ParentId   = taskProperties.JobId,
            };

            if (!string.IsNullOrWhiteSpace(taskProperties.TaskInstanceName))
            {
                timelineRecord.Name = taskProperties.TaskInstanceName;
            }

            // this is an upsert call
            await taskClient.UpdateTimelineRecordAsync(timelineRecord, cancellationToken).ConfigureAwait(false);
        }