Skip to content

Instantly share code, notes, and snippets.

@antonfirsov
Created March 7, 2020 02:06
Show Gist options
  • Save antonfirsov/bed737bcf31c0690918bb893e0005c7a to your computer and use it in GitHub Desktop.
Save antonfirsov/bed737bcf31c0690918bb893e0005c7a to your computer and use it in GitHub Desktop.
using System;
using System.Diagnostics.Tracing;
namespace EtwTest
{
[EventSource]
public class TestEventSource : EventSource
{
public static readonly TestEventSource Log = new TestEventSource();
public static class Keywords
{
public const EventKeywords Glory = (EventKeywords) 1;
public const EventKeywords Shame = (EventKeywords) 2;
}
[Event(1, Keywords = Keywords.Glory, Level = EventLevel.LogAlways)]
public void Hello(string contextObject, string message)
{
WriteEvent(1, contextObject, message);
}
[Event(2, Keywords = Keywords.Glory, Level = EventLevel.LogAlways)]
public void Goodbye(string contextObject, int levelOfGlory)
{
WriteEvent(2, contextObject, levelOfGlory);
}
[Event(3, Keywords = Keywords.Shame, Level = EventLevel.LogAlways)]
public void Goodbye2(int levelOfShame, int destroyWorld)
{
WriteEvent(3, levelOfShame, destroyWorld);
}
}
class Program
{
static void Main(string[] args)
{
using var process = System.Diagnostics.Process.GetCurrentProcess();
Console.WriteLine($"PID={process.Id} | Press enter to start!");
Console.ReadLine();
Program program = new Program();
program.Run(666);
}
private void Run(int x)
{
TestEventSource.Log.Hello("1", "test");
int y = x + 1;
Console.WriteLine("oookaaaaay");
TestEventSource.Log.Goodbye("1", y);
TestEventSource.Log.Goodbye2(y, 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment