Simplest way to write a log message and display in Perfview

断了今生、忘了曾经 提交于 2019-12-02 08:02:24

What you want is to use EventSource. Here you don't need to deal with GUIDs and registration to system.

public sealed class MinimalEventSource : EventSource
{
    public class Tasks
    {
        public const EventTask Information = (EventTask)1;
    }

    public static MinimalEventSource Log = new MinimalEventSource();

    [Event(1, Message = "{0}", Opcode = EventOpcode.Info, Task = Tasks.Information)]
    public void Information(string message)
    {
        if (IsEnabled())
        {
            WriteEvent(1, message);
        }
    }
}

Lof the data with MinimalEventSource.Log.Information("my debug info"); and capture them with perfview with PerfView /OnlyProviders=*MinimalEventSource. The imprtant thing is the * . Eventsource logs the Manifest with the definitions via ManifestEvent which gets added to the ETL, so no manifest registration is required.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!