Search code examples
.netazure-storagewadslogtable

Deleting records from Azure Storage WADSLogTable and WADWindowsEventLogsTable


Looking to programmatically do in .NET as question states. Which libraries should I be looking into? Links to code examples much appreciated.

Thanks.


Solution

  • You can refer to the simple example as below, it truncates the table based upon a timestamp and then scan the table to get the data.

        public void TruncateDiagnostics(CloudStorageAccount storageAccount, DateTime keepThreshold)
        {
                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
    
                CloudTable cloudTable = tableClient.GetTableReference("WADLogsTable");
    
                TableQuery query = new TableQuery();
                query.FilterString = string.Format("Timestamp lt datetime'{0:yyyy-MM-ddTHH:mm:ss}'", keepThreshold);
                var items = cloudTable.ExecuteQuery(query).ToList();
    
                Dictionary<string, TableBatchOperation> batches = new Dictionary<string, TableBatchOperation>();
                foreach (var entity in items)
                {
                    TableOperation tableOperation = TableOperation.Delete(entity);
    
                    if (!batches.ContainsKey(entity.PartitionKey))
                    {
                        batches.Add(entity.PartitionKey, new TableBatchOperation());
                    }
    
                    batches[entity.PartitionKey].Add(tableOperation);
                }
    
                foreach (var batch in batches.Values)
                {
                    cloudTable.ExecuteBatch(batch);
                }
        }
    

    You can get more examples from this thread Windows Azure - Cleaning Up The WADLogsTable.