User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 422,554 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,626 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums

Making a log file global

Join Date: Jun 2005
Posts: 69
Reputation: DotNetUser is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
DotNetUser DotNetUser is offline Offline
Junior Poster in Training

Making a log file global

  #1  
Apr 24th, 2006
I'm coding in VC++.NET 2003. I have a class that needs a log file to log info and errors for debugging. The problem I have is that FileStream and StreamWriter can not be global. I get compiler error C3145 : cannot declare a global or static managed type object or a __gc pointer. A workaround was to open, write, and then close the log file in every function/event. During testing, I discovered that this won't work since other functions/events may be executed before the previous function/event has closed the file. Any suggestions?

  FileStream* fs = new FileStream(S"c:\\Variables.txt", FileMode::Append, FileAccess::Write, FileShare::Write);
  fs->Close();
  StreamWriter* sw = new StreamWriter(S"c:\\Variables.txt", true, Encoding::ASCII);
  String* NextLine=S"This is the appended line.";
  sw->Write(NextLine);
  sw->Close();
Last edited by Dave Sinkula : Apr 25th, 2006 at 9:50 am.
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 12:58 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC