我正在尝试使用提供的解决方案从我的WADLogsTable中删除数据here
我已经修改了一下来调用developmentstorage但是代码抛出异常而远程服务器返回了一个错误:(400)Bad Request。说“其中一个请求输入超出范围。”执行此行代码后if(items.Count()== 0)
以下是我的代码
public static async void TruncateDiagnostics()
{
Uri test = new Uri("http://127.0.0.1:10002/Tables/");
while (true)
{
try
{
// Retrieve storage account from connection-string
CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
Microsoft.WindowsAzure.Storage.Table.CloudTableClient tableClientObj = new Microsoft.WindowsAzure.Storage.Table.CloudTableClient(test);
CloudTable cloudTable = tableClientObj.GetTableReference("wadlogstable");
// keep a hours worth of logs
DateTime keepThreshold = DateTime.UtcNow.AddHours(-1);
// do this until we run out of items
while (true)
{
TableQuery query = new TableQuery();
query.FilterString = string.Format("PartitionKey < '0{0}'", keepThreshold.Ticks);
var items = cloudTable.ExecuteQuery(query);
if (items.Count() == 0)
break;
Dictionary<string, TableBatchOperation> batches = new Dictionary<string, TableBatchOperation>();
foreach (var entity in items)
{
TableOperation tableOperation = TableOperation.Delete(entity);
// need a new batch?
if (!batches.ContainsKey(entity.PartitionKey))
batches.Add(entity.PartitionKey, new TableBatchOperation());
// can have only 100 per batch
if (batches[entity.PartitionKey].Count < 100)
batches[entity.PartitionKey].Add(tableOperation);
}
// execute!
foreach (var batch in batches.Values)
await cloudTable.ExecuteBatchAsync(batch);
Trace.TraceInformation("WADLogsTable truncated: " + query.FilterString);
}
}
catch (Exception ex)
{
Trace.TraceError("Truncate WADLogsTable exception {0}", ex.Message);
}
// run this once per day
await Task.Delay(TimeSpan.FromDays(1));
}
}
我现在已经坚持这个问题了一段时间。任何帮助将不胜感激。 提前谢谢。
答案 0 :(得分:0)
尝试:
query.FilterString = string.Format("PartitionKey gt '0{0}'", keepThreshold.Ticks);
query.FilterString = string.Format("PartitionKey lt '0{0}'", keepThreshold.Ticks);
在您的foreach循环
之前不会执行查询