Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to output to console from within a class library C#?

Tags:

c#

console

Is it possible to output values to the console from within a class library?

For example

 Console App -> calls method in -> assembly > function

Is it possible to write a console.out method in the function of the assembly?

I know in web its possible to get the httpcontext, and do a response.write.

like image 709
JL. Avatar asked Aug 17 '09 14:08

JL.


2 Answers

Yup, Console.WriteLine etc will work just fine in a class library... but there's no guarantee that anything is listening to the console. If you use it from a WinForms app or a web app, that output may well go absolutely nowhere...

Have you thought of using a logging library such as log4net instead?

like image 176
Jon Skeet Avatar answered Sep 30 '22 19:09

Jon Skeet


It depends on what type of application is going to use your class library. If it is used in a console application, then the output will be printed to the console. If it is a WinForms, Windows Service or ASP.NET application the output will be ignored.

like image 26
Darin Dimitrov Avatar answered Sep 30 '22 18:09

Darin Dimitrov