Rich Text Box on Existing Form

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Rich Text Box on Existing Form

spickles
I have created a target that points to an existing form and existsing control.  However, when I load the application, I get a second NLog RTB that pops out and it writes to that rather than to my existing RTB.  How to I prevent the second window and use the existing one?  I thought it was pretty clear that all I need to do is add the target and use the name of the existing control.  Here's my config:

<target xsi:type="RichTextBox"
          name="LogToRTB"
          layout="${date:format=MM-dd-yyyy HH\:mm\:ss} [${uppercase:${level}}] ${message}"
          height="300"
          autoScroll="true"
          maxLines="10"
          showMinimized="false"
          toolWindow="true"
          controlName="richTextBox1"
          formName="Form1"
          width="744"
          useDefaultRowColoringRules="false">
      <row-coloring backgroundColor="Black" condition="level==LogLevel.Trace" fontColor="Magenta"
                 style="Regular"/>
      <row-coloring backgroundColor="White" condition="level==LogLevel.Debug" fontColor="Green"
                 style="Regular"/>
      <row-coloring backgroundColor="White" condition="level==LogLevel.Info" fontColor="Black"
                 style="Regular"/>
      <row-coloring backgroundColor="Black" condition="level==LogLevel.Warn" fontColor="Yellow"
                 style="Regular"/>
      <row-coloring backgroundColor="White" condition="level==LogLevel.Error" fontColor="Red"
                 style="Regular"/>
      <row-coloring backgroundColor="Red" condition="level==LogLevel.Fatal" fontColor="White"
                 style="Regular"/>
    </target>

<rules>
    <logger name="*" minlevel="Trace" writeTo="LogToRTB" />
  </rules>
Reply | Threaded
Open this post in threaded view
|

Re: Rich Text Box on Existing Form

spickles
I'm also setting <targets async="true"> if that matters.
Reply | Threaded
Open this post in threaded view
|

Re: Rich Text Box on Existing Form

Jason LaFlair
Administrator
In reply to this post by spickles
I would try to add the full name of the form "MyApp.Form1" or "MyApp.Form1, MyApp" and see of that resolves your issue.
Reply | Threaded
Open this post in threaded view
|

Re: Rich Text Box on Existing Form

spickles
No, neither works.
Reply | Threaded
Open this post in threaded view
|

Re: Rich Text Box on Existing Form

spickles
Ideally I want to be able to use this in a WPF application.  According to the following post, unless something has changed, it doesn't sound like it's going to work well (if at all).  The work around sounds pretty messy.

http://stackoverflow.com/questions/3705480/how-can-i-use-nlogs-richtextbox-target-in-wpf-application
Reply | Threaded
Open this post in threaded view
|

Re: Rich Text Box on Existing Form

spickles
Looks like NLog might not be able to find my form because the form isn't initialized until after NLog.  How do I initialize NLog after the form loads?
Reply | Threaded
Open this post in threaded view
|

Re: Rich Text Box on Existing Form

spickles
I think this is the issue I'm experiencing (see link).  I changed the initialization of my logger to after the 'InitializeComponent()' method of my form, but it didn't seem to matter.

http://nlog.codeplex.com/workitem/2707