Exemplo n.º 1
0
 private void LogTextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (LogTextBox.Text.Length != 0)
     {
         LogTextBox.ScrollToLine(LogTextBox.LineCount - 2);
     }
 }
Exemplo n.º 2
0
        private void ReadLog()
        {
            var newLogFile = Logging.LogFile;

            if (newLogFile != _currentLogFile)
            {
                _currentOffset      = 0;
                _currentLogFile     = newLogFile;
                _currentLogFileName = Logging.LogFileName;
            }

            try
            {
                if (!File.Exists(newLogFile))
                {
                    Title = $@"{this.GetWindowStringValue(@"Title")}";
                    return;
                }
                using var reader = new StreamReader(new FileStream(newLogFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
                if (_currentOffset == 0)
                {
                    var maxSize = reader.BaseStream.Length;
                    if (maxSize > MaxReadSize)
                    {
                        reader.BaseStream.Seek(-MaxReadSize, SeekOrigin.End);
                        reader.ReadLine();
                    }
                }
                else
                {
                    reader.BaseStream.Seek(_currentOffset, SeekOrigin.Begin);
                }

                var txt = reader.ReadToEnd();
                if (!string.IsNullOrEmpty(txt))
                {
                    LogTextBox.AppendText(txt);

                    if (LogTextBox.SelectionStart == 0 || LogTextBox.IsScrolledToEnd())
                    {
                        LogTextBox.ScrollToEnd();
                    }
                    else
                    {
                        LogTextBox.ScrollToLine(LogTextBox.GetLineIndexFromCharacterIndex(LogTextBox.SelectionStart));
                    }
                }

                _currentOffset = reader.BaseStream.Position;
            }
            catch (FileNotFoundException)
            {
            }
            catch (ArgumentNullException)
            {
            }

            Title = $@"{this.GetWindowStringValue(@"Title")} {_currentLogFileName}";
        }
Exemplo n.º 3
0
 private void LogTextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (LogTextBox.Text.Length != 0)
     {
         if (Log.Contains("Раунд 3"))
         {
             LogTextBox.ScrollToLine(LogTextBox.LineCount - 1);
         }
         else
         {
             LogTextBox.ScrollToLine(LogTextBox.LineCount - 2);
         }
     }
 }
Exemplo n.º 4
0
 private void Log(string str)    // потоки
 {
     try
     {
         this.Dispatcher.Invoke(() =>
         {
             LogTextBox.AppendText(DateTime.Now.ToString("HH:mm:ss.fff") + " " + str + Environment.NewLine);
             LogTextBox.ScrollToLine(LogTextBox.LineCount - 1);  // прокрутка scroll
         });
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
 private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
 {
     LogTextBox.ScrollToLine(LogTextBox.LineCount - 1);
 }