I want to update a very old C# WinForms project which uses Microsoft.WindowsAzure.Storage library to use the "newest" possible Azure storage library Azure.Storage. I'm using .Net Framework 4.8.
One of the operations I'm not able to replace seems to be the Microsoft.WindowsAzure.Storage.OperationContext. We did log all the retries in the old app and I was wondering if this is still possible? How should I log errors or success with the new library?
Old code:
var context = new OperationContext();
context.ClientRequestID = myid; //"some request id";
context.Retrying += (sender, args) =>
{
int retryCnt = context.RequestResults.Count;
ErrorMessage("Upload failed. Start Retry " + retryCnt + " for BLOB: " + blobName, myid);
};
// define action when request is completed -> the request is also completed when the upload failed
context.RequestCompleted += (sender, args) =>
{
/* Collect operation completion information */
if (args.Response != null)
{
DebugMessage("Upload completed for BLOB " + blobName, myid);
}
else
{
int retryCnt = context.RequestResults.Count - 1;
ErrorMessage("Upload failed (Retry " + retryCnt + ") for BLOB " + blobName, myid);
}
};
I implemented retries with azure.storage using:
BlobContainerClient container = null;
var options = new BlobClientOptions();
options.Retry.MaxRetries = 4;
/* Create Handle to storage container using the sas to identify */
try
{
container = new BlobContainerClient(new Uri(sasToken),options);
}
catch (Exception ex)
{
ErrorMessage("container reference couldn't be set" + ex.Message, String.Empty);
}
Unfortunately I couln't find any good documentations on the retry topic.
I tried the below Winforms .Net Framework 4.8. code with the newest Azure storage library and retry logic for uploading blob.
csproj :
MainForm.cs :
Output :
It ran successfully as shown below. Then, I clicked on Upload button. The blob uploaded successfully.
The blob was uploaded successfully to the storage account in the Azure portal.