This Gist shows how to output trace messages to Process Monitor at runtime. Writing trace messages to Process Monitor will let you see how process events correlate to parts of your program.
Using the ProcessMonitor class is fairly easy. For example, the following program outputs three trace messages to Process Monitor:
internal class Program
{
private void Main()
{
using (var procmon = new ProcessMonitor())
{
procmon.WriteMessage("The program is starting.");
Thread.Sleep(5000);
procmon.WriteMessage("The program is running.");
Thread.Sleep(5000);
procmon.WriteMessage("The program is ending.");
}
}
}
In order to see the trace messages in the Process Monitor log, you must enable profiling events. If you do not enable profiling events, the events will still be captured and added to the log, but the events will be filtered out from being displayed in the Process Monitor viewer.