0

I am trying to use EventSource with Microsoft.Diagnostics.EventFlow and I cannot make it output to the console. Here is an example where it works with Inputs.Trace but does not work with 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);
    }
}

console app:

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");
    }
}

in the console app, I am using both EventSource and Trace as inputs, however only the Trace one is shown in the console. What am I doing wrong with the EventSource that it does not show up in the console?

Thanks!

4

1 回答 1

1

I found the problem, and that was the configuration file. The sources part should go inside of the inputs part. So, there should be only inputs and outputs collection in the configuration file. The working configuration for the EventSource as the input, and StdOutput as output looks like this:

myEventFlowConfig.json:

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

"outputs": [
    {
        "type": "StdOutput"
    }
]
}
于 2020-01-22T08:15:54.157 回答