How to set log logs in a WindowsForm textbox

54 views
Skip to first unread message

Fellipe Pinheiro

unread,
Mar 3, 2017, 12:34:58 PM3/3/17
to Fellow Oak DICOM
I'm creating an interface to the Print SCP project sample and would like the logs to be shown in a WindowsForm TextBox.

I tried to change this method, but it did not work.
// Initialize log manager.
LogManager.SetImplementation (ConsoleLogManager.Instance);

Does anyone know how to do this?
When starting Print SCP the logs are registered in the textBox.



Anders Gustafsson Cureos AB

unread,
Mar 5, 2017, 10:52:16 AM3/5/17
to Fellow Oak DICOM
Hi Fellipe,

if I am not mistaken, you will also need to redirect the console output to a text writer that you have tied up with your GUI text box.

Can't find any good examples right now, but MSDN documentation should hopefully lead you on the right track.

Best regards,
Anders @ Cureos

Fellipe Pinheiro

unread,
Mar 8, 2017, 2:41:17 PM3/8/17
to Fellow Oak DICOM
I create a class 
public class TextBoxStreamWriter : TextWriter
   
{
       
TextBox _output = null;


       
public TextBoxStreamWriter(TextBox output)
       
{
            _output
= output;
       
}
       
       
public override void Write(char value)
       
{
           
base.Write(value);
           
//_output.AppendText(value.ToString());
            _output
.Invoke((MethodInvoker)(() => _output.AppendText(value.ToString())));
       
}


       
public override Encoding Encoding
       
{
           
get { return Encoding.UTF8; }
       
}
   
}

and set Console output
Console.SetOut(new TextBoxStreamWriter(txtLog));


Reply all
Reply to author
Forward
0 new messages