예제 #1
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;

            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);
        }
예제 #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);
        }