I'm hoping to have a simple function (not a class or library) that lets me dump information to a text file as I'm executing, but easier said than done. There are plenty of questions about stream writers, but somehow none of them are doing what I'm looking for:
public partial class MainWindow : Window
{
// Make true for logging
private bool diag = true;
private StreamWriter logger = null;
public MainWindow()
{
logger = new StreamWriter(regStuff.MyDocsPath() + @"\Paneless\log.txt");
}
private void Log(string toLog)
{
if (diag)
logger.WriteLine(toLog);
}
}
In theory, with the above, I should be able to call "Log" with a string at any point in my code to have it dump a bit of diagnostic code to the text file. It doesn't work and I can't figure out why. From the guides, this seems correct. I've seen some that use a "using" statement, but do I really want to have a hundred of those one after the other? Seems... inefficient.