Beispiel #1
0
        /// <summary>
        /// Log the message to the the correct path
        /// </summary>
        /// <param name="message"></param>
        /// <param name="level"></param>
        /// <param name="reportModification"></param>
        private void Log(string message, LogLevel level, bool reportModification)
        {
            lock (this.guardMutex)
            {
                //Don't overwhelm the logging system
                if (debugSettings.VerboseLogging)
                {
                    InstrumentationLogger.LogPiiInfo("LogMessage-" + level.ToString(), message);
                }

                switch (level)
                {
                //write to the console
                case LogLevel.Console:
                    if (ConsoleWriter != null)
                    {
                        try
                        {
                            ConsoleWriter.AppendLine(string.Format("{0}", message));
                            FileWriter.WriteLine(string.Format("{0} : {1}", DateTime.UtcNow.ToString("u"), message));
                            FileWriter.Flush();
                            RaisePropertyChanged("ConsoleWriter");
                        }
                        catch
                        {
                            // likely caught if the writer is closed
                        }
                    }
                    break;

                //write to the file
                case LogLevel.File:
                    if (FileWriter != null)
                    {
                        try
                        {
                            FileWriter.WriteLine(string.Format("{0} : {1}", DateTime.UtcNow.ToString("u"), message));
                            FileWriter.Flush();
                        }
                        catch
                        {
                            // likely caught if the writer is closed
                        }
                    }
                    break;
                }

                if (reportModification)
                {
                    RaisePropertyChanged("LogText");
                }
            }
        }
Beispiel #2
0
        private void ExecThread()
        {
            Thread.Sleep(WARMUP_DELAY_MS);

            while (true)
            {
                try
                {
                    StabilityCookie.WriteUptimeBeat(DateTime.Now.Subtract(startTime));

                    //Disable heartbeat to avoid 150 event/session limit
                    //InstrumentationLogger.LogAnonymousEvent("Heartbeat", "ApplicationLifeCycle", GetVersionString());

                    String usage  = PackFrequencyDict(ComputeNodeFrequencies());
                    String errors = PackFrequencyDict(ComputeErrorFrequencies());

                    InstrumentationLogger.LogPiiInfo("Node-usage", usage);
                    InstrumentationLogger.LogPiiInfo("Nodes-with-errors", errors);

                    DynamoModel.OnRequestDispatcherInvoke(
                        () =>
                    {
                        string workspace =
                            dynamoModel.CurrentWorkspace
                            .GetStringRepOfWorkspace();
                        InstrumentationLogger.LogPiiInfo("Workspace", workspace);
                    });
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Exception in Heartbeat " + e);
                }

                // The following call will return "true" if the event is
                // signaled, which can only happen when "DestroyInternal"
                // is called as the application is shutting down. Otherwise,
                // when the wait time ellapsed, the loop continues to log
                // the next set of information.
                //
                if (shutdownEvent.WaitOne(HEARTBEAT_INTERVAL_MS))
                {
                    break;
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Notify the stability tracker that a crash has occured
 /// </summary>
 public void NotifyCrash()
 {
     InstrumentationLogger.LogAnonymousTimedEvent(
         "Stability", "TimeBetweenFailure", timeSinceLastCrash.Elapsed);
     timeSinceLastCrash.Restart();
 }
Beispiel #4
0
        /// <summary>
        /// Start up and report the status of the last shutdown
        /// </summary>
        public static void Startup()
        {
            StabilityUtils.IsLastShutdownClean = IsLastShutdownClean();
            String cleanShutdownValue = Registry.GetValue(REG_KEY, SHUTDOWN_TYPE_NAME, null) as String;
            String uptimeValue        = Registry.GetValue(REG_KEY, UPTIME_NAME, null) as String;

            bool     isUptimeSpanValid = false;
            TimeSpan uptimeSpan        = TimeSpan.MinValue;


            long uptimeMs;

            if (long.TryParse(uptimeValue, out uptimeMs))
            {
                uptimeSpan        = TimeSpan.FromMilliseconds(uptimeMs);
                isUptimeSpanValid = true;
            }

            if (cleanShutdownValue == null || uptimeValue == null)
            {
                InstrumentationLogger.LogAnonymousEvent("FirstTimeStartup", "Stability");
            }
            else
            {
                switch (cleanShutdownValue)
                {
                case CLEAN_SHUTDOWN_VALUE:
                    InstrumentationLogger.LogAnonymousEvent("Clean shutdown", "Stability");
                    if (isUptimeSpanValid)
                    {
                        InstrumentationLogger.LogAnonymousTimedEvent("Stability", "Clean Uptime", uptimeSpan);
                    }
                    break;

                case CRASHING_SHUTDOWN_VALUE:
                    InstrumentationLogger.LogAnonymousEvent("Crashing shutdown", "Stability");
                    if (isUptimeSpanValid)
                    {
                        InstrumentationLogger.LogAnonymousTimedEvent("Stability", "Dirty Uptime", uptimeSpan);
                    }
                    break;

                case ASSUMING_CRASHING_SHUTDOWN_VALUE:
                    //This is the case where we don't know what happened, so we're defaulting
                    InstrumentationLogger.LogAnonymousEvent("Assumed crashing shutdown", "Stability");
                    if (isUptimeSpanValid)
                    {
                        InstrumentationLogger.LogAnonymousTimedEvent("Stability", "Assumed Dirty Uptime", uptimeSpan);
                    }
                    break;

                default:
                    //Something went wrong, fail out with 'unknown' data.
                    InstrumentationLogger.LogAnonymousEvent("Unknown shutdown", "Stability");
                    Debug.WriteLine("Unknown shutdown key value: " + cleanShutdownValue);
                    break;
                }
            }


            // If we don't do anything to explicitly set the type of shutdown assume we hard-crashed
            // this is pesimistic
            Registry.SetValue(REG_KEY, SHUTDOWN_TYPE_NAME, ASSUMING_CRASHING_SHUTDOWN_VALUE);
        }