-3

So, what i am trying to do is: I have a class in a other Project. I want to use my C# .Net Console App as some kind of Logger. I just want to output 2 things from the other class.

So: How can i output text in the Console from a other project's Class?

I tried alot. Yet i wasn't able to call the Console directly. I wanted to do for example:

CoolConsole.WriteLine("Hey"); 

but i wasn't able to call it.

Thanks alot!

burnsi
  • 6,194
  • 13
  • 17
  • 27
Adrian
  • 1
  • 1
  • *I tried alot.* So please show what you have tried so far and try to specify where you struggle. Please read [ask] and try to improve your question. – burnsi Jun 02 '22 at 15:13
  • In order to give you an accurate answer, we need to see your code. Otherwise we are guessing out of the blue. You have been downvoted, because you are not showing us the relevant code. Please, edit your question and add the relevant information. – Olivier Jacot-Descombes Jun 03 '22 at 09:17

1 Answers1

0

I assume that this other project defining the console is a class library.

You need a project reference to the other project if it is in the same solution. Otherwise add an assembly reference. I.e., add a reference to the DLL from the bin/Release folder.

Assuming that CoolConsole is a static class with static methods, import the namespace:

using TheOtherProject.TheNamespace;

Then you can do a call like CoolConsole.WriteLine("Hey");.

However, should the methods not be static, you must create an object first:

var console = new CoolConsole();
console.WriteLine("Hello");

Also, the class as well as the methods must be public to be accessible from another project (i.e., another assembly).

If your man app (executable) is not a console application itself, you must allocate a console using this answer from wizzardz to How do I show a console output/window in a forms application?

see also: Manage references in a project

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188