diff --git a/README.md b/README.md index fc6344f..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/live.gif "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/ @@ -119,6 +121,82 @@ public class FooTimeStampResolver : ILogEventInfoResolver 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/live.gif b/doc/images/live.gif deleted file mode 100644 index 5174420..0000000 Binary files a/doc/images/live.gif 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