I'm using a streamwriter in combination with a background worker, for logging.
As such, I have
System::Void
MyUI::execBWorker_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
String^ outputPath = _clr::Settings::ApplicationLogPath("_log.txt", true, false);
logfile_ = gcnew StreamWriter(outputPath,true);
DoStuff();
logfile_->Close();
}
Things in the DoStuff() method raise the Progress event.
System::Void
MyUI::execBWorker_ProgressChanged(System::Object^ sender, System::ComponentModel::ProgressChangedEventArgs^ e) {
logfile_->WriteLine("something");
}
I think this really smells. How can I make it better, or at least how can I check the logfile hasn't been closed? There are a lot of messages, so I'm concerned about opening and closing the logfile continuously.
If the StreamWriter
is closed, the BaseStream
property will return null
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With