예제 #1
0
        /// <nodoc />
        internal static void LogEvent(string eventName, AriaNative.EventProperty[] eventProperties)
        {
            if (!IsEnabled)
            {
                return;
            }

            AriaNative.LogEvent(s_ariaLogger, eventName, eventProperties);
        }
예제 #2
0
        /// <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;
            if (!IsEnabled)
            {
                return(ShutDownResult.Success);
            }

            lock (s_syncRoot)
            {
                if (s_hasBeenInitialized)
                {
                    Exception?     thrownException = null;
                    ShutDownResult shutDownResult  = ShutDownResult.Failure;
                    Task           shutdownTask    = Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            AriaNative.DisposeAriaLogger(s_ariaLogger);
                            s_ariaLogger   = IntPtr.Zero;
                            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);
        }
예제 #3
0
        private static void Initialize(string tenantToken, TimeSpan teardownTimeout)
        {
            lock (s_syncRoot)
            {
                // Initialization may only happen once per application lifetime so we need some static state to enforce this
                if (!s_hasBeenInitialized)
                {
                    Contract.RequiresNotNull(s_ariaTelemetryDBLocation);
                    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 = AriaNative.CreateAriaLogger(
                        tenantToken,
                        Path.Combine(s_ariaTelemetryDBLocation, s_ariaTelemetryDBName),
                        (int)teardownTimeout.TotalSeconds);
                    s_hasBeenInitialized = true;
                }
            }
        }