public void Stop() { EtwSession?.Dispose(); EtwSession = null; AppInsightsClient?.Flush(); AppInsightsConfig = null; }
public void Start() { if (!(TraceEventSession.IsElevated() ?? false)) { throw new SecurityException("Admin rights required to turn on ETW event monitoring"); } //https://docs.microsoft.com/en-us/azure/azure-monitor/app/console AppInsightsConfig = TelemetryConfiguration.Active; AppInsightsConfig.TelemetryInitializers.Add(new AppInsightsCloudIdInitializer()); AppInsightsClient = new TelemetryClient(AppInsightsConfig); AppInsightsClient.Context.GlobalProperties.Add("node", Environment.MachineName); AppInsightsClient.Context.GlobalProperties.Add("provider", ServiceFabricEtw.ProviderName); EtwSession?.Dispose(); EtwSession = new TraceEventSession(SessionName); //Note: TopShelf already calls Stop() when Cancel/unhandled exception occurs - so no need to do ETW cleanup as per: https://www.nuget.org/packages/Microsoft.Diagnostics.Tracing.TraceEvent.Samples/) //Use command line tool: "logman -ets" to monitor, and "logman -ets -stop ServiceFabric-Node-Monitor" to stop ETW sessions Task.Run(() => { EtwSession.Source.Dynamic.All += ServiceFabricTraceEvent; EtwSession.EnableProviderForOperationalChannel(); EtwSession.Source.Process(); }); }