Ok guys, this is very basic stuff I think.
I’m only getting familiar with C# and object oriented languages.
So here is a basic project I’m developping :
namespace MyProject
{
class MyProject
{
public Logger Logs = new Logger();
public WebServer Web = new WebServer();
static void Main()
{
// blabla
}
}
}
The logger is there to simply create a log file and when its “Add(string str)” method is called, it adds a line in the log file.
The webserver is my own webserver, opening a socket etc …
I’d like my webserver to be able to use my Add method of the logger… how am I supposed to achieve that ?
Inside my webserver class, using something like “MyProject.Logs.Add(string str)” doesn’t seem to work.
So how can I reference it ?
I don’t want to create a new instance of my Logger class inside my webserver, because I want to write everyting in the same text file (I might have more module running than just a webserver as well).
So I’d like to use the instance I created in my Main method, inside my Webserver class…
I hope this makes sense …
A couple of suggestions:
LogsandWebshould be private. Those are implementation details of your class. They’re nobody else’s business.Pass the instance of your logger to your web server:
Your web server can now have its very own copy: