Skip to content

Commit

Permalink
Handle UnauthorizedAccessException in ETWHelper (#3228)
Browse files Browse the repository at this point in the history
* catch UnauthorizedAccessException

* stop before showing error
  • Loading branch information
zadesai authored and EricJohnson327 committed Jun 14, 2024
1 parent d30b18e commit 51447fe
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions tools/PI/DevHome.PI/Helpers/ETWHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,27 @@ public void Start()
session.Dispose();
}

using (session = new TraceEventSession(sessionName))
try
{
// Filter the provider events based on processId
var providerOptions = new TraceEventProviderOptions { ProcessIDFilter = [targetProcess.Id] };
foreach (var provider in ProviderList)
using (session = new TraceEventSession(sessionName))
{
session.EnableProvider(provider, TraceEventLevel.Always, options: providerOptions);
// Filter the provider events based on processId
var providerOptions = new TraceEventProviderOptions { ProcessIDFilter = [targetProcess.Id] };
foreach (var provider in ProviderList)
{
session.EnableProvider(provider, TraceEventLevel.Always, options: providerOptions);
}

session.Source.Dynamic.All += EventsHandler;
session.Source.UnhandledEvents += UnHandledEventsHandler;
session.Source.Process();
}

session.Source.Dynamic.All += EventsHandler;
session.Source.UnhandledEvents += UnHandledEventsHandler;
session.Source.Process();
}
catch (UnauthorizedAccessException ex)
{
Stop();
WinLogsEntry entry = new(DateTime.Now, WinLogCategory.Error, ex.Message, WinLogsHelper.EtwLogsName);
output.Add(entry);
}
}
}
Expand Down

0 comments on commit 51447fe

Please sign in to comment.