I have a rather large program that have some odd behaviour once in a while. After it has been deployed at a customer it's not possible to do debugging. But it is permissible to use log files, so this is what I have created. Something like this:
TextWriter tw = new StreamWriter(@"C:\AS-log.txt", true);
tw.WriteLine("ValidateMetaData");
tw.Close();
3 lines like this has been inserted into the code at many places and do give excellent log information. There are 2 problems with this approach however:
- The code looks very messy when there are more lines regarding logging than actual code.
- I would like to be able to switch logging on and off via a configuration file.
Any suggestions to a way of logging that can do this and still be simple?