/// <summary> /// Sets a property on a concrete Aria event in combination with a PII (Personally Identifiable Information) type /// </summary> /// <param name="name">The name property</param> /// <param name="value">The value property</param> /// <param name="type">The PII type property</param> public void SetProperty(string name, string value, PiiType type) { #if !FEATURE_CORECLR m_eventProperties.SetProperty(name, value, ConvertPiiType(type)); #else #if PLATFORM_OSX AriaMacOS.SetStringPropertyWithPiiKind(m_eventProperties, name, value, (int)type); #endif #endif }
/// <summary> /// Sets a property on a concrete Aria event /// </summary> /// <param name="name">The name property</param> /// <param name="value">The value property</param> public void SetProperty(string name, string value) { #if !FEATURE_CORECLR m_eventProperties.SetProperty(name, value); #else #if PLATFORM_OSX AriaMacOS.SetStringProperty(m_eventProperties, name, value); #endif #endif }
/// <summary> /// Initializes an underlaying, platform specific Aria event /// </summary> /// <param name="name">The event name</param> /// <param name="targetFramework">The target framework to create the Aria logging facilities for</param> /// <param name="targetRuntime">TThe target runtime to create the Aria logging facilities for</param> public AriaEvent(string name, string targetFramework, string targetRuntime) { m_targetFramework = targetFramework; m_targetRuntime = targetRuntime; #if !FEATURE_CORECLR m_eventProperties = new EventProperties(name); #else #if PLATFORM_OSX m_eventProperties = AriaMacOS.CreateEvent(name); #endif #endif }
/// <summary> /// Sends the concrete Aria event to the remote telemetry stream /// </summary> public void Log() { #if !FEATURE_CORECLR LogManager.GetLogger().LogEvent(m_eventProperties); #else #if PLATFORM_OSX AriaMacOS.LogEvent(AriaV2StaticState.s_AriaLogger, m_eventProperties); // Free the native Aria event AriaMacOS.DisposeEvent(m_eventProperties); m_eventProperties = IntPtr.Zero; #endif #endif }
/// <summary> /// Ensure that all events are sent and shuts down telemetry. This should be done before the application exits. /// It should not be called if the application will log any more telemetry events in the future /// </summary> public static ShutDownResult TryShutDown(TimeSpan timeout, out Exception exception) { exception = null; lock (s_syncRoot) { if (s_hasBeenInitialized) { Exception thrownException = null; ShutDownResult shutDownResult = ShutDownResult.Failure; Task shutdownTask = Task.Factory.StartNew(() => { try { #if FEATURE_ARIA_TELEMETRY #if !FEATURE_CORECLR LogManager.FlushAndTearDown(); #else #if PLATFORM_OSX AriaMacOS.DisposeAriaLogger(s_AriaLogger); s_AriaLogger = IntPtr.Zero; #endif #endif #endif shutDownResult = ShutDownResult.Success; } catch (Exception ex) { thrownException = ex; shutDownResult = ShutDownResult.Failure; } }); bool finished = shutdownTask.Wait(timeout); if (!finished) { // The telemetry client API doesn't provide a better way to cancel the shutdown. Leaving it // dangling isn't great, but the process is about to shut down anyway. shutDownResult = ShutDownResult.Timeout; } return(shutDownResult); } } return(ShutDownResult.Success); }
private static void Initialize(string tenantToken) { lock (s_syncRoot) { // Initialization may only happen once per application lifetime so we need some static state to enforce this if (!s_hasBeenInitialized) { #if FEATURE_ARIA_TELEMETRY #if !FEATURE_CORECLR LogConfiguration configuration = new LogConfiguration() { PerformanceCounter = new PerformanceCounterConfiguration() { Enabled = false, } }; LogManager.Initialize(tenantToken, configuration); #else #if PLATFORM_OSX Contract.Requires(s_ariaTelemetryDBLocation != null); if (s_ariaTelemetryDBLocation.Length > 0 && !Directory.Exists(s_ariaTelemetryDBLocation)) { Directory.CreateDirectory(s_ariaTelemetryDBLocation); } // s_ariaTelemetryDBLocation is defaulting to an empty string when not passed when enabling telemetry, in that case // this causes the DB to be created in the current working directory of the process s_AriaLogger = AriaMacOS.CreateAriaLogger(tenantToken, System.IO.Path.Combine(s_ariaTelemetryDBLocation, s_ariaTelemetryDBName)); #endif #endif #endif s_hasBeenInitialized = true; } } }