Microsoft.Diagnostics.EventFlow 和 Inputs.EventSource

Microsoft.Diagnostics.EventFlow with Inputs.EventSource

我正在尝试将 EventSourceMicrosoft.Diagnostics.EventFlow 一起使用,但无法将其输出到控制台。这是一个示例,它适用于 Inputs.Trace 但不适用于 Inputs.EventSource:

myEventFLowConfig.json:

{
"type": "EventSource",

"sources": [
    {
        "providerName": "MyCompanyEventSource"
    }
],

"inputs":
[
    {
        "type": "EventSource",
        "traceLevel": "Warning"
    },
    {
        "type": "Trace",
        "traceLevel": "Warning"
    }
],

"outputs": [
    {
        "type": "StdOutput"
    }
]

}

MyEventSource.cs

[EventSource(Name = "MyCompanyEventSource")]
public class MyEventSource : EventSource
{
    public static MyEventSource Log = new MyEventSource();

    [Event(250, Message = "MESSAGE FROM EVENT SOURCE", Level = EventLevel.Warning)]
    public void MessageFromEventSource()
    {
        WriteEvent(250);
    }
}

控制台应用程序:

public class Program
{
    static void Main(string[] args)
    {
        using (var pipeline = DiagnosticPipelineFactory.CreatePipeline("myEventFlowConfig.json"))
        {
            SomeMethod();
            Console.WriteLine("Press any key to exit...");                
            Console.ReadKey(intercept: true);
        }

    }

    private static void SomeMethod()
    {
        MyEventSource.Log.MessageFromEventSource();
        System.Diagnostics.Trace.TraceWarning("MESSAGE FROM TRACE");
    }
}

在控制台应用程序中,我同时使用 EventSourceTrace 作为输入,但是只有 Trace 一个显示在控制台中。 EventSource 没有显示在控制台中,我做错了什么?

谢谢!

我找到了问题,那就是配置文件。 sources 部分应该放在 inputs 部分里面。因此,配置文件中应该只有 inputsoutputs 集合。 EventSource 作为输入,StdOutput 作为输出的工作配置如下所示:

myEventFlowConfig.json:

{
"inputs": [
    {
        "type": "EventSource",
        "sources": [
            {
                "providerName": "MyCompanyEventSource",
                "traceLevel": "Warning"
            }
        ]
    }
],

"outputs": [
    {
        "type": "StdOutput"
    }
]
}