azure - 如何在 Azure 服务总线中使用/启用 EventHubClient 的 EventHubsEventSource 跟踪

标签 azure azure-eventhub

在EventHubClient(来自Azure SDK)(LINK)的源代码中,我看到部分函数调用中有诊断跟踪。我想知道如何启用此功能,以便痕迹显示在某处。

最佳答案

I want to find out how I can enable this so that the traces show up somewhere.

您需要实现一个 EventListener 将日志保存到您想要的任何位置。以下是将日志写入文件的示例。

public sealed class FileEventListener : EventListener
{
    private string _filePath;

    public FileEventListener(string name)
    {
        this._filePath = name;
    }

    private void WriteToFile(string message)
    {
        File.AppendAllText(_filePath, DateTime.Now.ToString() + message + "\n");
    }

    protected override void OnEventWritten(EventWrittenEventArgs eventData)
    {
        WriteToFile(string.Format(eventData.Message, eventData.Payload.ToArray()));  
    }

    protected override void OnEventSourceCreated(EventSource eventSource)
    {

    }
}

实现您自己的EventListener后,您可以在您的应用程序中使用它。

EventListener myFileListener = new FileEventListener("D:\\log.txt");
myFileListener.EnableEvents(EventHubsEventSource.Log, EventLevel.LogAlways);

关于azure - 如何在 Azure 服务总线中使用/启用 EventHubClient 的 EventHubsEventSource 跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45447054/

相关文章:

c# - 将 CORS 添加到索引时(以编程方式)Azure.Search.Documents 引发错误

azure-functions - 带有事件中心触发器的 Azure 函数写入重复的消息

c# - azure 事件中心中的纪元、序列号、偏移量、所有者、 token 意味着什么?

javascript - 如何使用node.js将blob移动到Azure中的子目录中

asp.net-mvc - token 获取过程中未找到缓存 token

python-3.x - 无法在 python 中迭代 Azure ADGroupPaged 对象

azure - 通过流分析按条件在 sql 表中插入/更新来自 iohub 的引用数据

azure - Azure.Messaging.EventHubs.Producer 命名空间中的 EventDataBatch.TryAdd() 问题

c# - 错误 : Azure. Messaging.EventHubs : The path to an Event Hub may be specified as part of the connection string or as a separate value, 但不是两者

azureservicebus - 事件中心异常 :Cannot allocate more handles to the current session or connection