Skip to content

Commit

Permalink
Skip debug logging in release builds, change log limiting method
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffthiele committed Dec 11, 2017
1 parent 415ff07 commit bb5c722
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions WindowPositionReset/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Windows.Threading;
using System.Drawing;
using System.IO;
using System.Text;
using log4net;
using log4net.Config;
using Microsoft.Win32;
Expand Down Expand Up @@ -46,13 +47,15 @@ public MainWindow()

XmlConfigurator.Configure();

#if DEBUG
foreach (var appender in LogManager.GetRepository().GetAppenders())
{
if (appender is EventTriggerAppender eta)
{
eta.OnLogEvent += Appender_OnLogEvent;
}
}
#endif

InitializeComponent();
this.WindowState = System.Windows.WindowState.Minimized;
Expand Down Expand Up @@ -114,14 +117,15 @@ public MainWindow()

private void Appender_OnLogEvent(object sender, string message)
{
txtLog.Text += message;
var value = txtLog.Text + message;

if (txtLog.Text.Length > MaxLogLength)
if (value.Length > MaxLogLength)
{
txtLog.Text = txtLog.Text.Substring(txtLog.Text.Length - MaxLogLength);
txtLog.Text = txtLog.Text.Substring(txtLog.Text.IndexOf('\n') + 1);
value = value.Substring(value.Length - MaxLogLength);
value = value.Substring(value.IndexOf('\n') + 1);
}

txtLog.Text = value;
logViewer.ScrollToBottom();
}

Expand Down

0 comments on commit bb5c722

Please sign in to comment.