I have try something on System.IO class to create a file in ASCII format. Unfortunately, I can't get it done. Something wrong with my code. Could anyone give me some advices?
Code:
protected LogWriter logWriter;
bool dirExists = validateDir(); // Create directory if not exist
if (dirExists) {
bool fileExists = validateFile(); // Create file if not found
if (fileExists) {
StreamWriter sw = new StreamWriter(file, true, System.Text.Encoding.ASCII);
logWriter = new LogWriter(sw);
logWriter.log("Test1");
}
}
// Class LogWriter
public class LogWriter {
private TextWriter tw;
public LogWriter(TextWriter tw) {
this.tw = tw;
}
public void log (string message) {
tw.WriteLine("[{0} : {1}] =>", DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString());
tw.WriteLine("{0}", message);
tw.WriteLine("\n");
tw.Flush();
tw.Close();
}
}
// End Class LogWriter
The output :
[Saturday, December 11, 2004 : 11:42:58 PM] =>
Test 1(square box)
Remark : (square box) is represent a square box when I use notepad to open the output file.
Thanks.