Skip to content

Instantly share code, notes, and snippets.

@krist00fer
Created October 15, 2015 14:26
Show Gist options
  • Save krist00fer/c56abc107827817178fe to your computer and use it in GitHub Desktop.
Save krist00fer/c56abc107827817178fe to your computer and use it in GitHub Desktop.
Sample program on how to use Azure Append Blob. Perfect for "ever growing" files like: log-files, etc.
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using System;
namespace AppendBlobSample
{
class Program
{
private static string StorageAccountName = "put-your-storage-account-name-here";
private static string StorageAccountAccessKey = "put-your-storage-account-access-key-here";
static void Main(string[] args)
{
var credentials = new StorageCredentials(StorageAccountName, StorageAccountAccessKey);
var account = new CloudStorageAccount(credentials, useHttps: true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference(containerName: "tmp");
container.CreateIfNotExists();
var blob = container.GetAppendBlobReference(blobName: "log.txt");
if (!blob.Exists()) blob.CreateOrReplace();
Console.WriteLine("Enter various lines of text. End with an empty line.");
string txt;
while (!string.IsNullOrWhiteSpace(txt = Console.ReadLine()))
{
blob.AppendText(txt + Environment.NewLine);
}
Console.WriteLine("Blob now contains");
Console.WriteLine(blob.DownloadText());
Console.WriteLine("Press any key to exit");
Console.ReadKey(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment