我正在尝试从我们办公室的桌面存储中提取一些数据。除了时间戳之外,我可以使每种类型的查询都能正常工作。他们不断给我一个HTTP错误400错误的请求。检查时,确切的错误文本是
“'时间戳eq中第20位的语法错误 2018-06-04T12:05:31.9150000Z”。 请求ID:3949e07b-b002-003f-59f8-065461000000 时间:2018-06-18T11:38:28.7307368Z ”
我访问特定数据的代码是;
var lowerlimit = DateTime.Now.AddDays(-20);
TableQuery<LogEntity> query = new TableQuery<LogEntity>().Where(TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThan, lowerlimit));
作为示例,此代码有效;
TableQuery<LogEntity> query = new TableQuery<LogEntity>().Where(TableQuery.GenerateFilterCondition("Level", QueryComparisons.Equal, "Warn"));
我找不到和我一样有问题的人,所以我希望你能帮助我!提前谢谢!
*edit* here is the full code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure; // Namespace for CloudConfigurationManager
using Microsoft.Azure.Storage; // Namespace for StorageAccounts
using Microsoft.Azure.CosmosDB.Table; // Namespace for Table storage types
using Newtonsoft.Json;
namespace DataPullingViregoLog
{
class Program
{
static void Main(string[] args)
{
var lowerlimit = DateTimeOffset.Now.AddDays(-20);
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudTableClient tableClient =
storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "people" table.
CloudTable table = tableClient.GetTableReference("{dbname}");
TableQuery<LogEntity> query = new TableQuery<LogEntity>
().Where(TableQuery.GenerateFilterConditionForDate("Timestamp",
QueryComparisons.GreaterThan, lowerlimit));
IEnumerable<LogEntity> table2 = table.ExecuteQuery(query);
var listOfEntities = new List<LogEntity>();
foreach (LogEntity entity in table2)
{
listOfEntities.Add(entity);
Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey,
entity.RowKey,
entity.Level, entity.MessageWithLayout);
}
var convertedJson = JsonConvert.SerializeObject(listOfEntities,
Formatting.Indented);
}
}
internal class LogEntity : TableEntity
{
public LogEntity(string PartitionKey, string Rowkey, DateTime Timestamp)
{
this.PartitionKey = PartitionKey;
this.RowKey = RowKey;
this.Timestamp = Timestamp;
}
public LogEntity() { }
public string LogTimeStamp { get; set; }
public string Level {get;set;}
public string LoggerName { get; set; }
public string Message { get; set; }
public string MessageWithLayout { get; set; }
public string MachineName { get; set; }
public long LogTimeTicks { get; set; }
public string Exception { get; set; }
}
/拉斯穆斯
答案 0 :(得分:0)
根据您的描述,我假设您正在使用Azure cosmos table(Microsoft.Azure.CosmosDB.Table)SDK来操作Azure存储帐户。
如果您要操作Azure存储表,请使用WindowsAzure.Storage, 它与您提到的库不同。
我建议您可以创建一个安装了WindowsAzure.Storage 9.20的新项目,然后它应该可以正常工作。
答案 1 :(得分:0)
因此,我发现需要另一个库,该库未在任何Microsoft指南中显示。这就是我的最终代码的样子。谢谢你的协助!显然,唯一需要的是using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.Azure;