NLog DiagnosticListener for DiagnosticSource



是否有任何 NLog 包提供与日志 .NET 诊断源模型的本机集成?有点像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}nt{string.Join("nt", currentActivity.Tags)}");
});
}
});

https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md#discovery-of-diagnosticlisteners

https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/develop/Src/Web/Web/AspNetDiagnosticTelemetryModule.cs

设置观察器(所需的侦听器(的示例:

https://github.com/NLog/NLog.DiagnosticSource/blob/master/test/NLog.DiagnosticSource.Tests/DiagnosticListenerTargetTests.cs

侦听来自目标的输出(相反的方式(:

https://github.com/NLog/NLog.DiagnosticSource/blob/master/src/NLog.DiagnosticSource/Targets/DiagnosticListenerTarget.cs

相关内容

  • 没有找到相关文章

最新更新