I created a new target class called "ScreenTarget". I just based it on the MessageBoxTarget class (it's not a descendant of MessageBoxTarget - I just copied the source file and modified it.)
In order to make it work in a thread-safe manner, I needed a delegate that the ScreenTarget.Write() method could call, and I needed a way to marshall the call back to the UI thread.
To do this, I created a new component that descends from the RichTextBox component, and called it ScreenTargetBox. I also added a field to the ScreenTarget class that takes a reference to a ScreenTargetBox object.
I extended the ScreenTargetBox control by adding a method called "void writeLog( string logMsg )". I also added a delegate definition, and a class data member that refers to an instance the delegate (created in the constructor) by pointing it to the writeLog() method.
The writeLog() method just calls "this.AppendText(logMsg + "\r\n");".
To make it work, after creating a ScreenTarget object, you have to set its "TargetBox" property to an instance of ScreenTargetBox. The ScreenTarget object can then call TargetBox.Invoke(TargetBox.logMessage, <text>).
I'm still considering a different approach, but for now, this is working. (Having a custom control as the "on-screen viewer" would alllow the ability to color-code certain types of items, based on the log text, which can be customized via a layout, etc., but I'm not 100% sure this is the best way to do it...).
Anyway, when I get code more stable I will be glad to contribute it. I will let you know.
It's still unreleased, yet but does most of what you want to achieve. The application sends logging events over the network using the UDP protocol and NLogViewer receives them, parses and displays applying coloring, filtering and so on. Most features are not working yet, but as far as viewing and coloring is concerned it's pretty usable.
Thanks, Jarek. The NLog Viewer looks like a great app, and I can think of several applications for it.
Does it use NLog to display log entries received over the network? If so, I assume then that it uses a Target that displays to a screen window. Perhaps I could just use that target.
If it doesn't use NLog to display log entries, then it's probably not quite what I am looking for... I need a way for an application's internal logging to not only go to disk, but also to a screen control (one that scrolls in real-time) with the same level of control, filtering, and configurability as other NLog targets.
I had also considered creating a SysLog target so that NLog could log to any SysLog viewer... is this how the NLog Viewer works? Does it include a target for the logging app?