Utility class to support analytics tracking.
Exemplo n.º 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)
                {
                    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 only
                case LogLevel.ConsoleOnly:
                    if (ConsoleWriter != null)
                    {
                        try
                        {
                            ConsoleWriter.AppendLine(string.Format("{0}", message));
                            RaisePropertyChanged("ConsoleWriter");
                        }
                        catch
                        {
                            // likely caught if the writer is closed
                        }
                    }
                    break;

                //write to both console and file
                case LogLevel.Console:
                    if (ConsoleWriter != null && FileWriter != 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");
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Shuts down the client. Application life cycle end is tracked.
 /// </summary>
 internal static void ShutDown()
 {
     Analytics.ShutDown();
 }