// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using Microsoft.PowerToys.Telemetry.Events; namespace Microsoft.PowerToys.Telemetry { /// /// Telemetry helper class for PowerToys. /// public class PowerToysTelemetry : TelemetryBase { /// /// Name for ETW event. /// private const string EventSourceName = "Microsoft.PowerToys"; /// /// Initializes a new instance of the class. /// public PowerToysTelemetry() : base(EventSourceName) { } /// /// Gets an instance of the class. /// public static PowerToysTelemetry Log { get; } = new PowerToysTelemetry(); /// /// Publishes ETW event when an action is triggered on /// [UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", Justification = "We will ensure the public properties won't be trimmed by ourself.")] public void WriteEvent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(T telemetryEvent) where T : EventBase, IEvent { if (DataDiagnosticsSettings.GetEnabledValue()) { this.Write( telemetryEvent.EventName, new EventSourceOptions() { Keywords = ProjectKeywordMeasure, Tags = ProjectTelemetryTagProductAndServicePerformance, }, telemetryEvent); } } } }