From: Bill on
Hello

I've got a C# console app, that calls a startup function in a C# dll that I
have created. In my DLL, as I'm processing data, I want to display some
logging information, but I want to pass it back to the console app, and have
it write the text to the console as it comes from the DLL, but I'm not sure
how I should do this....

Any suggestions, example


Thanks


From: Peter Duniho on
Bill wrote:
> Hello
>
> I've got a C# console app, that calls a startup function in a C# dll that I
> have created. In my DLL, as I'm processing data, I want to display some
> logging information, but I want to pass it back to the console app, and have
> it write the text to the console as it comes from the DLL, but I'm not sure
> how I should do this....

Do you want to pass it back to the console application? Or do you want
the text to show up in the console? If you are passing the text to the
application, you cannot enforce any rule that it has to then show the
text in the console. On the other hand, if you always want the text to
go to the console, you can just call the Console.WriteLine() method
directly (or similar).

My preference would be for a DLL to not be printing stuff to the console
unless that's specifically the point of the DLL. If you have a more
general desire to provide a mechanism for logging/diagnostic information
to flow from the DLL, it would be better to have the client code (the
application itself) pass an instance of TextWriter to the DLL, which the
DLL can then use to write output.

If the client code wants console output, it can just pass the value of
Console.Out. Otherwise, it can provide its own TextWriter and consume
the output however it wants.

Pete
From: Bill on
The DLL, isn't going to actually do the printing to a console window,
instead it should pass text strings back to the calling app, and then the
calling app would print the string to the console window.


"Peter Duniho" <NpOeStPeAdM(a)NnOwSlPiAnMk.com> wrote in message
news:oYKdnQlsXvZYU7HRnZ2dnUVZ_o-dnZ2d(a)posted.palinacquisition...
> Bill wrote:
>> Hello
>>
>> I've got a C# console app, that calls a startup function in a C# dll that
>> I have created. In my DLL, as I'm processing data, I want to display
>> some logging information, but I want to pass it back to the console app,
>> and have it write the text to the console as it comes from the DLL, but
>> I'm not sure how I should do this....
>
> Do you want to pass it back to the console application? Or do you want
> the text to show up in the console? If you are passing the text to the
> application, you cannot enforce any rule that it has to then show the text
> in the console. On the other hand, if you always want the text to go to
> the console, you can just call the Console.WriteLine() method directly (or
> similar).
>
> My preference would be for a DLL to not be printing stuff to the console
> unless that's specifically the point of the DLL. If you have a more
> general desire to provide a mechanism for logging/diagnostic information
> to flow from the DLL, it would be better to have the client code (the
> application itself) pass an instance of TextWriter to the DLL, which the
> DLL can then use to write output.
>
> If the client code wants console output, it can just pass the value of
> Console.Out. Otherwise, it can provide its own TextWriter and consume the
> output however it wants.
>
> Pete


From: Peter Duniho on
Bill wrote:
> The DLL, isn't going to actually do the printing to a console window,
> instead it should pass text strings back to the calling app, and then the
> calling app would print the string to the console window.

Then just have the calling app pass a TextWriter instance. If the
calling app wants the text to go to the console, they can just pass the
value of Console.Out, as I mentioned before.

Pete
From: Mr. Arnold on
Bill wrote:
> Hello
>
> I've got a C# console app, that calls a startup function in a C# dll that I
> have created. In my DLL, as I'm processing data, I want to display some
> logging information, but I want to pass it back to the console app, and have
> it write the text to the console as it comes from the DLL, but I'm not sure
> how I should do this....
>
> Any suggestions, example
>
>
> Thanks
>
>

You're easiest option would be to make a public object with get/set for
string value and pass the object between the console app and the dll.
You would instantiate the object in the console app and send it (by ref)
to the dll.

You come out of the dll back to the console app and print what's in the
object's string property.