.net core 如何在.net core 2.2(运行时事件)中使用EventListener

.net core 如何在.net core 2.2(运行时事件)中使用EventListener,.net-core,.net-core-2.2,.net Core,.net Core 2.2,微软宣布发布.NETCore2.2。它包括对运行时的诊断改进,使用运行时事件,我的问题是:如何在.NET Core 2.2中使用EventListener?这篇文章很差。我实际上是在一个ASP.NETCore2.2API示例项目中得到的。这其实相当容易,但我也需要一些时间 我创建了一个类似于文档中提到的diagnostics类。我将该类命名为Diagnostics.cs。该类包含Microsoft文档中的代码。不多不少。 我在ConfigureServices()中将其添加为单例服务 当从邮递员

微软宣布发布.NETCore2.2。它包括对运行时的诊断改进,使用
运行时事件
,我的问题是:如何在.NET Core 2.2中使用EventListener?这篇文章很差。

我实际上是在一个ASP.NETCore2.2API示例项目中得到的。这其实相当容易,但我也需要一些时间

我创建了一个类似于文档中提到的diagnostics类。我将该类命名为
Diagnostics.cs
。该类包含Microsoft文档中的代码。不多不少。 我在ConfigureServices()中将其添加为单例服务

当从邮递员那里到达终点时,我得到了很多事件

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"
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)”
Name=“InlineNamespace”Value=“Microsoft.IntelliTrace.TelemetryObserver.MvcActionEventArgumentSerializer”
Name=“InlineName”Value=“SerializeArguments”
Name=“InlineNameSignature”Value=“class-System.String(class-System.Collections.Generic.IEnumerable`1)”
Name=“InlineNamespace”Value=“System.Collections.Generic.IEnumerator`1[System.Collections.Generic.KeyValuePair`2[System.\uu Canon,System.\uu Canon]]”
Name=“inlineName”Value=“获取当前值”
Name=“inlineNameSignature”Value=“实例!0()”
Name=“FailAlways”Value=“False”
Name=“FailReason”Value=“目标不直接”
Name=“ClrInstanceID”Value=“8”

当然,这只是为了测试目的。我可能不会将其添加为singleton,而是尝试将其改为泛型/类型化,并将其添加为作用域服务或临时服务

感谢Dan,链接说:这些事件描述了GC、JIT、线程池和互操作的行为。现在我想获得关于这些的运行时信息,你能更清楚地描述它吗?如果你按照我在回答中所描述的做,你会看到这种类型的信息:GC、JIT、Threadpool。我还写了一篇博文。也许会更清楚:
private Diagnostics _diag;
        public ValuesController(Diagnostics diag)
        {
            _diag = diag;
        }
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"