0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C# Azure Storageでシステムログ(.log)をダウンロードする

Posted at

logファイルの種類が追加Blob(AppendBlob)の場合は、CloudAppendBlobを使用する。imageの場合は、ブロックBlob(BlockBlob)であったので、CloudBlockBlobを使用。image fileと同じだと思って、CloudBlockBlobを使おうとしたら以下のエラーメッセージがでて少しはまった。

Blob type of the blob reference doesn't match blob type of the blob

image.png

public static void DownloadLog(string filename)
{
	CloudBlobContainer container = GetBlobContainer("log");

	// ダウンロードするファイル名を指定
	CloudAppendBlob appendBlob_download = container.GetAppendBlobReference(filename);

	//ダウンロード後のパスとファイル名を指定。
	string path = Directory.GetCurrentDirectory() + "\\log\\" + DateTime.Now.ToString("yyyyMMdd") + ".log";

	appendBlob_download.DownloadToFile(path, FileMode.CreateNew);

}
private static CloudBlobContainer GetBlobContainer(string folder)
{
    // Retrieve storage account from connection string.
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    	CloudConfigurationManager.GetSetting("StorageConnectionString"));

    // Create the blob client.
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

    // Retrieve a reference to a container.
    CloudBlobContainer container = blobClient.GetContainerReference(folder);
    
    return container;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?