troubleshooting Question

Creating a Log Writer That 2 Application Write to at the Same Time C#

Avatar of npl77
npl77 asked on
4 Comments1 Solution924 ViewsLast Modified:
I have created a client/server appilcation that I am trying to debug, so  decided to create a simple  logger class to log whats going on in my code. What I think a problem is gonna be is I want the client app and the server app to write to 1 log file. Both apps will of course be running at the same time. What do I have to do to make this work because if I instanciate the logger class in the server app and then instanciate the same class in the client app without closing the StreamWriter, I think the code is gonna break. I attached my simple logger class below.
class Logger
        TextWriter tw;
        public Logger()
            tw = new StreamWriter(@"D:\Profiles\w6068c\Desktop\NLogFile.txt");
        public void WriteToLogFile(string message,string sender)
            tw.WriteLine(sender+ "/n" +message);
        public void CloseLogger()
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros