Esempio n. 1
0
        /// <summary>
        /// Logs to file and displays the specified message in the log textbox.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="logType">The log type.</param>
        private void Log(string message, LogType logType)
        {
            // Log to file
            Logger logger = LogManager.GetCurrentClassLogger();

            logger.Log(logType.ToNLogLevel(), message);

            // Log to window
            if (App.UserSettings.ShowVerboseLog || logType == LogType.Error || logType == LogType.Info || logType == LogType.IntermediateSuccess || logType == LogType.Success)
            {
                // Time
                var textRange = new TextRange(richTextBoxLog.Document.ContentEnd, richTextBoxLog.Document.ContentEnd)
                {
                    Text = DateTime.Now.ToString("HH:mm:ss") + " "
                };
                textRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Gray);
                // Message
                textRange = new TextRange(richTextBoxLog.Document.ContentEnd, richTextBoxLog.Document.ContentEnd)
                {
                    Text = message
                };
                textRange.ApplyPropertyValue(TextElement.ForegroundProperty, LogHelper.GetColor(logType));
                // Line break
                richTextBoxLog.AppendText(Environment.NewLine);

                if (richTextBoxLog.IsScrolledToEnd())
                {
                    richTextBoxLog.ScrollToEnd();
                }
            }
        }