我會建議調查StorageException
類,尤其是RequestInformation
該類的成員是類型RequestResult
。它包含有關錯誤的有用信息。
下面是一個例子。
static void UnderstandStorageException()
{
var cred = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("container");
var blockBlob = container.GetBlockBlobReference("something.txt");
try
{
blockBlob.UploadFromFile(@"D:\test.txt");
blockBlob.AcquireLease(TimeSpan.FromSeconds(10), Guid.NewGuid().ToString());
blockBlob.Delete();
}
catch (StorageException excep)
{
var requestInformation = excep.RequestInformation;
Console.WriteLine(requestInformation.HttpStatusCode);
Console.WriteLine(requestInformation.HttpStatusMessage);
Console.WriteLine(requestInformation.ExtendedErrorInformation.ErrorCode);
Console.WriteLine(requestInformation.ExtendedErrorInformation.ErrorMessage);
}
}
在這種情況下,我試圖獲得blob的租約,但我指定了10秒作爲無效輸入的租期。這將導致來自Azure存儲的400
狀態碼。當我執行代碼時,我得到以下信息:
HTTP Status Code: 400
HTTP Status Message: The value for one of the HTTP headers is not in the correct format.
Storage Error Code: InvalidHeaderValue
Storage Error Message: The value for one of the HTTP headers is not in the correct format.
RequestId:04969aab-0001-001c-5965-6df5fe000000
Time:2017-01-13T06:23:25.4667820Z
謝謝!這給了我可以用來改善我的搜索的一些即時信息。 –