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 @@ - - - - - - - - - - - - - - + +