【发布时间】:2018-12-06 00:36:03
【问题描述】:
MS 宣布发布 .NET Core 2.2。它包括对运行时的诊断改进,Runtime Events,我的问题是:如何在 .NET Core 2.2 中使用 EventListener?文章很差。
【问题讨论】:
MS 宣布发布 .NET Core 2.2。它包括对运行时的诊断改进,Runtime Events,我的问题是:如何在 .NET Core 2.2 中使用 EventListener?文章很差。
【问题讨论】:
我实际上是在一个示例 ASP.Net Core 2.2 API 项目中使用它。这实际上相当容易,但我也需要一些时间。
我创建了一个诊断类,就像文档中提到的那样。我将该类命名为Diagnostics.cs。该类包含 Microsoft 文档中的代码。不多也不少。
我在 ConfigureServices() 中将其添加为单例服务。
services.AddSingleton<Diagnostics>();
最后我将它注入到 ValuesController 中。
private Diagnostics _diag;
public ValuesController(Diagnostics diag)
{
_diag = diag;
}
从 Postman 访问端点时,我收到了很多事件。
ThreadID = 13588 ID = 192 Name = MethodJitInliningFailed
Name = "MethodBeingCompiledNamespace" Value = "Microsoft.IntelliTrace.TelemetryObserver.MvcActionEventArgumentSerializer"
Name = "MethodBeingCompiledName" Value = "SerializeArguments"
Name = "MethodBeingCompiledNameSignature" Value = "class System.String (class System.Collections.Generic.IEnumerable`1<value class System.Collections.Generic.KeyValuePair`2<class System.String,class System.Object>>)"
Name = "InlinerNamespace" Value = "Microsoft.IntelliTrace.TelemetryObserver.MvcActionEventArgumentSerializer"
Name = "InlinerName" Value = "SerializeArguments"
Name = "InlinerNameSignature" Value = "class System.String (class System.Collections.Generic.IEnumerable`1<value class System.Collections.Generic.KeyValuePair`2<class System.String,class System.Object>>)"
Name = "InlineeNamespace" Value = "System.Collections.Generic.IEnumerator`1[System.Collections.Generic.KeyValuePair`2[System.__Canon,System.__Canon]]"
Name = "InlineeName" Value = "get_Current"
Name = "InlineeNameSignature" Value = "instance !0 ()"
Name = "FailAlways" Value = "False"
Name = "FailReason" Value = "target not direct"
Name = "ClrInstanceID" Value = "8"
这当然仅用于测试目的。我可能不会将其添加为单例,而是尝试使其成为通用/类型化并将其添加为范围或瞬态服务。
【讨论】: