aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication/Logging/LogForm.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-02-13 23:00:13 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-02-13 23:00:13 -0500
commita4b40ad9d90a40cd5e35bb7b9c43ad436e992cd4 (patch)
tree84a697bf606b293c3e74d7757b28d3bb40d1d269 /MediaBrowser.ServerApplication/Logging/LogForm.cs
parent58a46171ababb816636a65aa7f76c00de50f598f (diff)
handle year in name when searching
Diffstat (limited to 'MediaBrowser.ServerApplication/Logging/LogForm.cs')
-rw-r--r--MediaBrowser.ServerApplication/Logging/LogForm.cs88
1 files changed, 88 insertions, 0 deletions
diff --git a/MediaBrowser.ServerApplication/Logging/LogForm.cs b/MediaBrowser.ServerApplication/Logging/LogForm.cs
new file mode 100644
index 000000000..a8813406a
--- /dev/null
+++ b/MediaBrowser.ServerApplication/Logging/LogForm.cs
@@ -0,0 +1,88 @@
+using MediaBrowser.Common.Implementations.Logging;
+using MediaBrowser.Model.Logging;
+using NLog.Targets;
+using System;
+using System.ComponentModel;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace MediaBrowser.ServerApplication.Logging
+{
+ public partial class LogForm : Form
+ {
+ private readonly TaskScheduler _uiThread;
+ private readonly ILogManager _logManager;
+
+ public LogForm(ILogManager logManager)
+ {
+ InitializeComponent();
+
+ _logManager = logManager;
+ _uiThread = TaskScheduler.FromCurrentSynchronizationContext();
+ }
+
+ protected override void OnLoad(EventArgs e)
+ {
+ base.OnLoad(e);
+
+ ((NlogManager)_logManager).RemoveTarget("LogWindowTraceTarget");
+
+ ((NlogManager)_logManager).AddLogTarget(new TraceTarget
+ {
+ Layout = "${longdate}, ${level}, ${logger}, ${message}",
+ Name = "LogWindowTraceTarget"
+
+ }, LogSeverity.Debug);
+ }
+
+ /// <summary>
+ /// Logs the message.
+ /// </summary>
+ /// <param name="msg">The MSG.</param>
+ public async void LogMessage(string msg)
+ {
+ await Task.Factory.StartNew(() =>
+ {
+ if (listBox1.Items.Count > 10000)
+ {
+ //I think the quickest and safest thing to do here is just clear it out
+ listBox1.Items.Clear();
+ }
+
+ foreach (var line in msg.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
+ {
+ if (!string.IsNullOrWhiteSpace(line))
+ {
+ listBox1.Items.Insert(0, line);
+ }
+ }
+
+ }, CancellationToken.None, TaskCreationOptions.None, _uiThread);
+ }
+
+ /// <summary>
+ /// The log layout
+ /// </summary>
+ /// <value>The log layout.</value>
+ public string LogLayout
+ {
+ get { return "${longdate}, ${level}, ${logger}, ${message}"; }
+ }
+
+ /// <summary>
+ /// Shuts down.
+ /// </summary>
+ public async void ShutDown()
+ {
+ await Task.Factory.StartNew(Close, CancellationToken.None, TaskCreationOptions.None, _uiThread);
+ }
+
+ protected override void OnClosing(CancelEventArgs e)
+ {
+ base.OnClosing(e);
+
+ ((NlogManager)_logManager).RemoveTarget("LogWindowTraceTarget");
+ }
+ }
+}