1
- using Azure . Identity ;
1
+ using System . Diagnostics ;
2
+ using Azure . Identity ;
2
3
using Azure . Storage . Blobs ;
3
4
using Azure . Storage . Blobs . Models ;
4
5
using Azure . Storage . Blobs . Specialized ;
@@ -40,20 +41,45 @@ public async Task WriteToTargetAsync(Func<Stream, Task> writeToStream, IConfigur
40
41
41
42
logger . LogInformation ( "Saving file '{File}' to Azure Blob Container '{ContainerName}'" , settings . BlobName , settings . ContainerName ) ;
42
43
44
+ var lastLogTime = DateTime . MinValue ;
45
+ var logInterval = TimeSpan . FromMinutes ( 1 ) ;
46
+ long totalBytes = 0 ;
47
+
48
+ var sw = new Stopwatch ( ) ;
49
+ sw . Start ( ) ;
43
50
await using var blobStream = await blob . OpenWriteAsync ( true , new BlockBlobOpenWriteOptions
44
51
{
45
52
BufferSize = settings . MaxBlockSizeinKB * 1024L ,
46
53
ProgressHandler = new Progress < long > ( l =>
47
54
{
48
- logger . LogInformation ( "Transferred {UploadedBytes} bytes to Azure Blob" , l ) ;
55
+ if ( DateTime . UtcNow - lastLogTime >= logInterval )
56
+ {
57
+ logger . LogInformation ( "Transferred {TotalMiB} bytes to Azure Blob" , l / 1024 / 1024 ) ;
58
+ lastLogTime = DateTime . UtcNow ;
59
+ }
60
+
61
+ totalBytes = l ;
49
62
} )
63
+
50
64
} , cancellationToken ) ;
51
65
await writeToStream ( blobStream ) ;
66
+
67
+ sw . Stop ( ) ;
68
+
69
+ var totalMib = totalBytes / 1024 / 1024 ;
70
+ var rate = totalMib / sw . ElapsedMilliseconds / 1000 ;
71
+
72
+ logger . LogInformation ( "Transferred {TotalMiB} Mib to Azure Blob in {TotalTime} minutes ({Rate} MiB/s)." , totalMib , sw . ElapsedMilliseconds / 1000 / 60 , rate ) ;
52
73
}
53
74
54
75
public IEnumerable < IDataExtensionSettings > GetSettings ( )
55
76
{
56
77
yield return new AzureBlobSinkSettings ( ) ;
57
78
}
79
+
80
+ private void LogBytes ( )
81
+ {
82
+
83
+ }
58
84
}
59
85
}
0 commit comments