我已经构建了一个附加程序,它将 Log4Net 日志写入一个名为 LogTable 的 SimpleDB 表/域。我现在正在尝试编写一个 Windows 服务,该服务将从该表中删除旧记录。肯定会创建 AmazonSimpleDB 客户端,手动运行时的查询确实会返回记录。但是,当通过单元测试执行代码时,不会返回任何结果。表名和列名区分大小写是正确的。
using (AmazonSimpleDB simpleDbClient = AWSClientFactory.CreateAmazonSimpleDBClient(accessKey, secretKey))
{
String selectExpression = String.Format("select * from LogTable where Timestamp < '{0:o}'", purgeDate);
SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression);
SelectResponse selectResponse = simpleDbClient.Select(selectRequestAction);
if (selectResponse.IsSetSelectResult())
{
BatchDeleteAttributesRequest deleteRequest = new BatchDeleteAttributesRequest().WithDomainName("LogTable");
deleteRequest.Item = new List<DeleteableItem>();
SelectResult selectResult = selectResponse.SelectResult;
foreach (Item item in selectResult.Item)
{
deleteRequest.Item.Add(new DeleteableItem { ItemName = item.Name });
}
if (deleteRequest.Item.Count > 0)
{
simpleDbClient.BatchDeleteAttributes(deleteRequest);
}
logger.InfoFormat("Success - {0} log records deleted from LogTable", deleteRequest.Item.Count);
}
}
非常感谢对此提供一些帮助。