c# – Azure:以编程方式查询WADLogsTable以获取跟踪数据
发布时间:2020-12-15 08:34:52 所属栏目:百科 来源:网络整理
导读:我正在尝试使用以下代码从Azure获取最后一小时的所有跟踪数据: StorageCredentialsAccountAndKey storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(accountName,key); CloudStorageAccount csa = new CloudStorageAccount(storageCr
我正在尝试使用以下代码从Azure获取最后一小时的所有跟踪数据:
StorageCredentialsAccountAndKey storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(accountName,key); CloudStorageAccount csa = new CloudStorageAccount(storageCredentialsAccountAndKey,true); TableServiceContext tableServiceContext = new TableServiceContext(csa.TableEndpoint.ToString(),csa.Credentials); var results = tableServiceContext.CreateQuery<TableServiceEntity>("WADLogsTable").Where( x => x.Timestamp > DateTime.UtcNow.AddHours(-1)).ToList(); 但是,当我知道最后一小时表中有数据时,我发现没有找到结果(我将输出与Cerebrata的Azure诊断管理器进行比较). 我有两个问题: >这是查询WADLogsTable的正确方法吗?为什么我没有看到任何 解决方法
没有开箱即用的类型(类)代表WADLogs实体.使用基类,您将只获得PartionKey,RowKey和Timestamp属性.你必须自己定义它.这是我使用的示例:
public class WadLogEntity : Microsoft.WindowsAzure.StorageClient.TableServiceEntity { public WadLogEntity() { PartitionKey = "a"; RowKey = string.Format("{0:10}_{1}",DateTime.MaxValue.Ticks - DateTime.Now.Ticks,Guid.NewGuid()); } public string Role { get; set; } public string RoleInstance { get; set; } public int Level { get; set; } public string Message { get; set; } public int Pid { get; set; } public int Tid { get; set; } public int EventId { get; set; } public DateTime EventDateTime { get { return new DateTime(long.Parse(this.PartitionKey.Substring(1))); } } } 此外,当我在使用WADLogs表时,我设法使用此代码显示结果(过去24小时): var dtThen = DateTime.UtcNow.AddHours(-24); var dtNow = DateTime.UtcNow; var logs = this._wadLogs.WadLogs.Where( wl => wl.Level == 2 && String.Compare(wl.PartitionKey,"0" + dtThen.Ticks.ToString()) >=0 && String.Compare(wl.PartitionKey,"0" + dtNow.Ticks.ToString()) < 0 ).Take(200); 我注意到在滴答计数之前分区键中有一个“0”前缀. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |