Skip to content

Instantly share code, notes, and snippets.

@noahfalk
Created May 8, 2021 01:17
Show Gist options
  • Select an option

  • Save noahfalk/ca503276cea4b97c6630ebe672318ece to your computer and use it in GitHub Desktop.

Select an option

Save noahfalk/ca503276cea4b97c6630ebe672318ece to your computer and use it in GitHub Desktop.

Revisions

  1. noahfalk created this gist May 8, 2021.
    34 changes: 34 additions & 0 deletions Program.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    // Steps to run this sample:
    // 1. Create a console app and replace Program.cs with this source
    // 2. Build the app (for example with dotnet build). My exe is produced in
    // "E:\temp\EventSourceSample\bin\Debug\net5.0\EventSourceSample.exe"
    // 3. Download PerfView if you don't already have it: https://github.com/microsoft/perfview/blob/main/documentation/Downloading.md
    // 4. In an admin command prompt, run this PerfView command substituting the path to your executable:
    // PerfView.exe -OnlyProviders:MyEventSource run E:\temp\EventSourceSample\bin\Debug\net5.0\EventSourceSample.exe
    // 5. After PerfView finishes collecting, open the Events view and confirm that 1 event of type MyEventSource/HelloWorld was collected in
    // addition to the other events

    using System;
    using System.Diagnostics.Tracing;

    namespace EventSourceSample
    {
    class Program
    {
    static void Main(string[] args)
    {
    MyEventSource source = new MyEventSource();
    source.HelloWorld();
    }
    }

    [EventSource(Name="MyEventSource")]
    class MyEventSource : EventSource
    {
    [Event(1)]
    public void HelloWorld()
    {
    WriteEvent(1);
    }
    }
    }