.net - 诊断源的 NLog 诊断侦听器
问题描述
是否有任何 NLog 包提供与日志 .NET DiagnosticSource 模型的本机集成?有点像 NLogTraceListener ...
乍一看,在谷歌上看不到任何东西。
解决方案
也许您可以只执行 DiagnosticListener.AllListeners.Subscribe 然后转发到 NLog-Logger:
DiagnosticListener.AllListeners.Subscribe(delegate(DiagnosticListener listener)
{
// subscribe to the Service Bus DiagnosticSource
if (listener.Name == "Microsoft.Azure.ServiceBus")
{
// receive event from Service Bus DiagnosticSource
listener.Subscribe(delegate(KeyValuePair<string, object> @event)
{
// Log operation details once it's done
if (!@event.Key.EndsWith("Stop"))
return;
var currentActivity = Activity.Current;
NLogLogger.Debug($"{currentActivity.OperationName} Duration: {currentActivity.Duration}\n\t{string.Join("\n\t", currentActivity.Tags)}");
});
}
});
设置观察者(你想要的监听器)的例子:
监听来自目标的输出(相反的方式):
推荐阅读
- javascript - 将 javascript 对象从一种形式转换为另一种形式
- excel - 尝试使用 VBA 表单中的数据创建一个 excel 工作表,然后将其添加到工作簿的末尾
- html - Django 将 HTML 渲染为 PDF
- android - 如何为一系列工作人员调用 setForegroundAsync
- swift - 如何在swift中使用更少的参数创建闭包调用闭包
- python - 显示图表时无法更改线条粗细
- deep-learning - dm-sonnet=2.0.0 中的 snt.AbstractModule
- html - 单击搜索按钮后引导卡缩小
- javascript - 如何在不同的节点 js 路由上设置 cookie?
- node.js - 两个 tpc 在同一个端口上运行,nginx 和 digitalocean