diff --git a/README.md b/README.md
index b5e6545..18c383f 100644
--- a/README.md
+++ b/README.md
@@ -3,8 +3,10 @@
[3]: https://github.com/yarseyah/sentinel#nlogs-nlogviewer-target-configuration
[p1]: doc/images/control.png "NLogViewer"
-[p2]: doc/images/preview.gif "NLogViewer"
-[p3]: doc/images/control2.png "NLogViewer"
+[p2]: doc/images/overview.gif "NLogViewer"
+[p3]: doc/images/colors.png "NLogViewer"
+[p4]: doc/images/openpopup.gif "NLogViewer"
+[p5]: doc/images/newtask.gif "NLogViewer"
[nuget]: https://nuget.org/packages/Sentinel.NlogViewer/
@@ -20,16 +22,9 @@ NlogViewer
NlogViewer is a ui control library to visualize NLog logs in your personal application. It is mainly based on [Sentinel][1] and its controls.
-![NLogViewer][p2]
-
-Actually it contains the following controls:
-
-- `NLogViewer`
+supported Frameworks: `.NETCoreApp v3.0`, `.NETCoreApp v3.1`, `.NET Framework 4.6.1`
-Visual Studio
-
-![NLogViewer][p1]
-![NLogViewer][p3]
+![NLogViewer][p2]
## Quick Start
@@ -72,6 +67,136 @@ If you want to customize the `loggingPattern` and `LogLevel`, add the following
```
+## Customize
+
+### Colors
+
+Customize `foreground` or `background` of every `logLevel`
+
+![NLogViewer][p3]
+
+### Multi targeting
+
+Use more than one instance of `NLogViewer` to match different `rules`.
+
+Create 2 `targets` with their own `rules`.
+
+```xml
+
+
+
+
+
+
+
+
+
+```
+
+Set `TargetName` property to link them.
+
+```xml
+
+
+```
+
+### Format output (ILogEventInfoResolver)
+
+To format the output of a `LogEventInfo`, implement a new instance of `ILogEventInfoResolver` and bind it to the `Resolver` you want to customize:
+
+```csharp
+///
+/// Reformat the DateTime
+///
+public class FooTimeStampResolver : ILogEventInfoResolver
+{
+ public string Resolve(LogEventInfo logEventInfo)
+ {
+ return logEventInfo.TimeStamp.ToUniversalTime().ToString();
+ }
+}
+```
+
+```csharp
+NLogViewer1.TimeStampResolver = new FooTimeStampResolver();
+```
+
+## Samples
+
+### open on a new window
+
+![NLogViewer][p4]
+
+Create a new `Window` and add a default `NLogViewer`
+
+```csharp
+
+```
+
+Open the new `Window`
+
+```csharp
+TestPopup popup = new TestPopup();
+popup.Show();
+```
+
+### seperate logger for a task
+
+![NLogViewer][p5]
+
+Below is a sample how you could create a `NLogViewer` for a task
+
+```csharp
+// create unique target name
+var taskNumber = _RandomTaskCounter++;
+string targetName = $"task{taskNumber}";
+// create a unique logger
+var loggerName = $"MyFoo.Logger.{taskNumber}";
+var logger = LogManager.GetLogger(loggerName);
+
+// create new CacheTarget
+CacheTarget target = new CacheTarget
+{
+ Name = targetName
+};
+
+// get config // https://stackoverflow.com/a/3603571/6229375
+var config = LogManager.Configuration;
+
+// add target
+config.AddTarget(targetName, target);
+
+// create a logging rule for the new logger
+LoggingRule loggingRule = new LoggingRule(loggerName, LogLevel.Trace, target);
+
+// add the logger to the existing configuration
+config.LoggingRules.Add(loggingRule);
+
+// reassign config back to NLog
+LogManager.Configuration = config;
+
+// create a new NLogViewer Control with the unique logger target name
+NLogViewer nLogViewer = new NLogViewer
+{
+ TargetName = targetName,
+};
+
+// add it to the tab control
+var tabItem = new TabItem { Header = $"Task {taskNumber}", Content = nLogViewer };
+TabControl1.Items.Add(tabItem);
+TabControl1.SelectedItem = tabItem;
+
+// create task which produces some output
+var task = new Task(async () =>
+{
+ while (true)
+ {
+ logger.Info($"Hello from task nr. {taskNumber}. It's {DateTime.Now.ToLongTimeString()}");
+ await Task.Delay(1000);
+ }
+});
+```
+
## Why CacheTarget?
There is already a `NLogViewerTarget`, which is used for [Sentinel][1]. See [here][3]
diff --git a/doc/images/colors.png b/doc/images/colors.png
new file mode 100644
index 0000000..99e5546
Binary files /dev/null and b/doc/images/colors.png differ
diff --git a/doc/images/control.png b/doc/images/control.png
deleted file mode 100644
index ee7bbeb..0000000
Binary files a/doc/images/control.png and /dev/null differ
diff --git a/doc/images/control2.png b/doc/images/control2.png
deleted file mode 100644
index f7bbb94..0000000
Binary files a/doc/images/control2.png and /dev/null differ
diff --git a/doc/images/newtask.gif b/doc/images/newtask.gif
new file mode 100644
index 0000000..c955e1a
Binary files /dev/null and b/doc/images/newtask.gif differ
diff --git a/doc/images/openpopup.gif b/doc/images/openpopup.gif
new file mode 100644
index 0000000..a610f26
Binary files /dev/null and b/doc/images/openpopup.gif differ
diff --git a/doc/images/overview.gif b/doc/images/overview.gif
new file mode 100644
index 0000000..ddadae9
Binary files /dev/null and b/doc/images/overview.gif differ
diff --git a/doc/images/preview.gif b/doc/images/preview.gif
deleted file mode 100644
index 06e8cf3..0000000
Binary files a/doc/images/preview.gif and /dev/null differ
diff --git a/src/NLogViewer.TestApp/MainWindow.xaml b/src/NLogViewer.TestApp/MainWindow.xaml
index 10a8503..b6380ff 100644
--- a/src/NLogViewer.TestApp/MainWindow.xaml
+++ b/src/NLogViewer.TestApp/MainWindow.xaml
@@ -8,24 +8,30 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/NLogViewer.TestApp/MainWindow.xaml.cs b/src/NLogViewer.TestApp/MainWindow.xaml.cs
index 1748ff0..f5d1bfc 100644
--- a/src/NLogViewer.TestApp/MainWindow.xaml.cs
+++ b/src/NLogViewer.TestApp/MainWindow.xaml.cs
@@ -1,9 +1,15 @@
using System;
using System.Diagnostics;
using System.Reactive.Linq;
+using System.Threading.Tasks;
using System.Windows;
+using System.Windows.Controls;
+using DJ;
using DJ.Resolver;
+using DJ.Targets;
using NLog;
+using NLog.Config;
+using NLog.Filters;
namespace TestApplication
{
@@ -13,7 +19,7 @@ namespace TestApplication
public partial class MainWindow : Window
{
public const string LOREM_IPSUM = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
-
+
private readonly Logger _Logger = LogManager.GetCurrentClassLogger();
private readonly Logger _Logger2 = LogManager.GetLogger("Lorem.Ipsum.Foo.Hello.World.Lorem.Ipsum");
@@ -26,15 +32,15 @@ public MainWindow()
Title = $"Testing v{AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName}";
InitializeComponent();
DataContext = this;
-
+
NLogViewer1.TimeStampResolver = new FooTimeStampResolver();
Stopwatch stopwatch = Stopwatch.StartNew();
Random random = new Random();
- Observable.Interval(TimeSpan.FromMilliseconds(200)).ObserveOnDispatcher().Subscribe(l =>
+ Observable.Interval(TimeSpan.FromMilliseconds(200)).ObserveOnDispatcher().Subscribe(l =>
{
- if((_CntMessage == 10 || _CntError == 20) && TabControl1.Items.Count > 0)
- TabControl1.Items.RemoveAt(0);
- switch (random.Next(1,6))
+ //if((_CntMessage == 10 || _CntError == 20) && TabControl1.Items.Count > 0)
+ // TabControl1.Items.RemoveAt(0);
+ switch (random.Next(1, 6))
{
case 1:
_CntMessage++;
@@ -50,6 +56,7 @@ public MainWindow()
{
_Logger.Debug($"Hello everyone: {_CntMessage}");
}
+
break;
case 3:
_CntMessage++;
@@ -72,6 +79,7 @@ public MainWindow()
{
_Logger.Error(ex, $"There was an error on divison :/ {_CntError}");
}
+
break;
case 6:
_CntError++;
@@ -81,11 +89,70 @@ public MainWindow()
});
}
- private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
+ private void Button_OpenPopup_Click(object sender, RoutedEventArgs e)
{
TestPopup popup = new TestPopup();
popup.Show();
}
+
+ private void Button_AddTask_Click(object sender, RoutedEventArgs e)
+ {
+ AddNewTabWithLogger().Start();
+ }
+
+ private int _RandomTaskCounter;
+ private Task AddNewTabWithLogger()
+ {
+ // create unique target name
+ var taskNumber = _RandomTaskCounter++;
+ string targetName = $"task{taskNumber}";
+ // create a unique logger
+ var loggerName = $"MyFoo.Logger.{taskNumber}";
+ var logger = LogManager.GetLogger(loggerName);
+
+ // create new CacheTarget
+ CacheTarget target = new CacheTarget
+ {
+ Name = targetName
+ };
+
+ // get config // https://stackoverflow.com/a/3603571/6229375
+ var config = LogManager.Configuration;
+
+ // add target
+ config.AddTarget(targetName, target);
+
+ // create a logging rule for the new logger
+ LoggingRule loggingRule = new LoggingRule(loggerName, LogLevel.Trace, target);
+
+ // add the logger to the existing configuration
+ config.LoggingRules.Add(loggingRule);
+
+ // reassign config back to NLog
+ LogManager.Configuration = config;
+
+ // create a new NLogViewer Control with the unique logger target name
+ NLogViewer nLogViewer = new NLogViewer
+ {
+ TargetName = targetName,
+ };
+
+ // add it to the tab control
+ var tabItem = new TabItem { Header = $"Task {taskNumber}", Content = nLogViewer };
+ TabControl1.Items.Add(tabItem);
+ TabControl1.SelectedItem = tabItem;
+
+ // create task which produces some output
+ var task = new Task(async () =>
+ {
+ while (true)
+ {
+ logger.Info($"Hello from task nr. {taskNumber}. It's {DateTime.Now.ToLongTimeString()}");
+ await Task.Delay(1000);
+ }
+ });
+ return task;
+ }
}
///
@@ -98,4 +165,4 @@ public string Resolve(LogEventInfo logEventInfo)
return logEventInfo.TimeStamp.ToUniversalTime().ToString();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NLogViewer.TestApp/NLogViewer.TestApp.csproj b/src/NLogViewer.TestApp/NLogViewer.TestApp.csproj
index e35e1af..362324f 100644
--- a/src/NLogViewer.TestApp/NLogViewer.TestApp.csproj
+++ b/src/NLogViewer.TestApp/NLogViewer.TestApp.csproj
@@ -20,7 +20,7 @@
-
+
diff --git a/src/NLogViewer/NLogViewer.csproj b/src/NLogViewer/NLogViewer.csproj
index 31aa8e3..5d3572a 100644
--- a/src/NLogViewer/NLogViewer.csproj
+++ b/src/NLogViewer/NLogViewer.csproj
@@ -77,8 +77,8 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
+