/// <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) { Analytics.LogPiiInfo("LogMessage-" + level.ToString(), message); } // In test mode, write the logs only to std out. if (testMode) { Console.WriteLine(string.Format("{0} : {1}", DateTime.UtcNow.ToString("u"), message)); return; } 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"); } } }
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()); Analytics.LogPiiInfo("Node-usage", usage); Analytics.LogPiiInfo("Nodes-with-errors", errors); DynamoModel.OnRequestDispatcherInvoke( () => { string workspace = dynamoModel.CurrentWorkspace == null ? string.Empty : dynamoModel.CurrentWorkspace .GetStringRepOfWorkspace(); Analytics.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; } } }