【发布时间】:2018-10-10 16:28:47
【问题描述】:
是否有任何 NLog 包提供本地集成到日志 .NET DiagnosticSource 模型中?有点像 NLogTraceListener...
乍一看在谷歌上看不到任何东西。
【问题讨论】:
标签: .net nlog system.diagnostics
是否有任何 NLog 包提供本地集成到日志 .NET DiagnosticSource 模型中?有点像 NLogTraceListener...
乍一看在谷歌上看不到任何东西。
【问题讨论】:
标签: .net nlog system.diagnostics
也许你可以只执行 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)}");
});
}
});
设置观察者(你想要的监听器)的例子:
监听来自目标的输出(相反的方式):
【讨论】:
DiagnosticListener.AllListeners.Subscribe