From e0f70a7cda516f2cfcb48422c13833e4000618d0 Mon Sep 17 00:00:00 2001 From: Zac Brown Date: Fri, 6 Jan 2017 10:37:10 -0800 Subject: [PATCH] Add a CancelKeyPress event handler to properly stop trace. Signed-off-by: Zac Brown --- PowerShellMethodAuditor/Program.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/PowerShellMethodAuditor/Program.cs b/PowerShellMethodAuditor/Program.cs index 90a66d7..b527475 100644 --- a/PowerShellMethodAuditor/Program.cs +++ b/PowerShellMethodAuditor/Program.cs @@ -31,6 +31,14 @@ namespace PowerShellMethodAuditor trace.Enable(powershellProvider); + Console.CancelKeyPress += (sender, eventArg) => + { + if (trace != null) + { + trace.Stop(); + } + }; + // This is a blocking call. Ctrl-C to stop. trace.Start(); }