如何使用c#读取在blob中捕获的事件中心日志数据 [英] How do I read Event Hub log data which is capture in blob using c#
问题描述
我有 简单
逻辑应用创建
。
文本文件
I have simple
logic app
which creates
a text file
.
我想 测试
。
逻辑应用程序创建的文件是否存在于文件存储
并且还想测试 关联
逻辑app的id
我创建了 事件
集线器在
。
逻辑应用程序中配置诊断设置以流式传输到事件中心
I have created Event
Hub
and In
Logic app configure Diagnostic Settings to Stream to an event hub
.
现在 Inside
事件中心我已经为Azure存储配置了Capture选项,它将为事件日志创建一个blob文件
我想知道如何使用c#代码检查事件blob中的2件事情?
I wonder how can I check 2 things from event blob using c# code?
我想检查以下内容 -
I want to check following -
1.当Logic应用程序触发时,我想检查correlation_ID属性,我想我将从事件中心日志中获取。
1.When Logic app trigger I want to check correlation_ID property which I suppose I will get from event hub log.
-
在Logic应用程序中我创建了一个txt文件,我想从事件中心日志中获取新创建的文件名。
对上述两个问题有任何想法吗?
Any idea on above 2 questions ?
我试过这个 发布
但是每秒生成多个文件,究竟哪个文件包含我需要猜测的内容?
But there are multiple files generated per second and exactly which file contains what I need how to guess ?
代码效果很好 -
code works good -
var storageAccount = CloudStorageAccount.Parse(connectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
var blob = container.GetBlockBlobReference(blobName);
using (var stream = blob.OpenRead())
using (var reader = AvroContainer.CreateGenericReader(stream))
while (reader.MoveNext())
foreach (dynamic result in reader.Current.Objects)
{
var record = new AvroEventData(result);
record.Dump();
}
SE
SE
推荐答案
您好 ashuthinks32,
Hello ashuthinks32,
您可以使用容器的 ListBlobs 方法检索其中的blob日志要访问返回的IListBlobItem的丰富属性和方法集,必须将其强制转换为CloudBlockBlob。以下代码演示如何
检索并输出容器中每个项的URI:
You can use the container's ListBlobs method to retrieve the blob logs within it. To access the rich set of properties and methods for a returned IListBlobItem, you must cast it to a CloudBlockBlob.The following code demonstrates how to retrieve and output the URI of each item in the the container:
var storageAccount = CloudStorageAccount.Parse(connectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
container.CreateIfNotExists();
container.SetPermissions( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
var blobList = container.ListBlobs(null, true);
var latestBlob = blobList.Where(x => x.GetType() == typeof(CloudBlockBlob))
.Select( x => (CloudBlockBlob)x)
.OrderByDescending(x => x.Properties.LastModified).FirstOrDefault();
此外,似乎日志中没有任何 相关ID,至少我尚未找到属性:
In addition, it seems that there isn't any correlation id for the log,at least I have not found from the properties:
{
"CacheControl":null,
"ContentDisposition":null,
"ContentEncoding":null,
"ContentLanguage":null,
"Length":508,
"ContentMD5":null,
"ContentType":"application/octet-stream",
"ETag":"\"0x8D566F2FAFC1474\"",
"LastModified":"2018-01-29T08:33:32+00:00",
"BlobType":2,
"LeaseStatus":2,
"LeaseState":1,
"LeaseDuration":0,
"PageBlobSequenceNumber":null,
"AppendBlobCommittedBlockCount":null,
"IsServerEncrypted":true,
"IsIncrementalCopy":false,
"StandardBlobTier":1,
"RehydrationStatus":null,
"PremiumPageBlobTier":null,
"BlobTierInferred":true,
"BlobTierLastModifiedTime":null
}
最好的问候,
迈克尔
这篇关于如何使用c#读取在blob中捕获的事件中心日志数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!