WPF: binding RichTextBox to Logger output

I use NLog to log errors in my WPF application. The log is currently writing to a file. Now I have created a RichTextBox and want to write all the session logs to the RichTextBox at the same time. I created a wrapper over the NLog log, so I can include commands to write to another variable in the shell. But how do I bind?

Any help is appreciated

+1
source share
2 answers

I would try something like this:

Create a LogReader class to read with a log error, it should use StringReader or any reader you like. LogReader will basically provide you with a string with the contents of the file. Depending on your needs, and especially if the file is too large, you may need to break it into pieces, but I think you get this idea. Then you will have a ViewModel class that basically represents RichTextBox data

Now the tricky part is coming, but with this gem you can bind strings to RichTextBox.

<RichTextBox attached:RichTextboxAssistant.BoundDocument="{Binding LogMessages}"/>

NTN

0
source

I recently found this RichTextBox home target for nLog:

http://nlog.codeplex.com/workitem/6272?PendingVoteId=6272

I describe a way to make it work here .

0
source

All Articles