1
2
3
4
5
6 using System;
7
8 namespace System.IO
9 {
10 public class LogWriter
11 {
12 public LogWriter() :
13 logFilePath(), writer(Console.Out())
14 {
15 }
16 public LogWriter(const string& logFilePath_) :
17 logFilePath(logFilePath_), writer(SharedPtr<ByteStream>(new FileByteStream(logFilePath, cast<OpenMode>(OpenMode.append))))
18 {
19 }
20 public void Write(const string& str)
21 {
22 writer << str;
23 }
24 public void WriteLine(const string& str)
25 {
26 writer << str << endl();
27 writer.Flush();
28 }
29 public void WriteLine()
30 {
31 writer.WriteLine();
32 writer.Flush();
33 }
34 public inline nothrow const string& LogFilePath() const
35 {
36 return logFilePath;
37 }
38 public inline nothrow StreamWriter& GetStreamWriter()
39 {
40 return writer;
41 }
42 private string logFilePath;
43 private StreamWriter writer;
44 }
45
46 public LogWriter& operator<<(LogWriter& writer, const string& str)
47 {
48 writer.Write(str);
49 return writer;
50 }
51
52 public LogWriter& operator<<(LogWriter& writer, char c)
53 {
54 writer.Write(ToString(c));
55 return writer;
56 }
57
58 public LogWriter& operator<<(LogWriter& writer, bool b)
59 {
60 writer.Write(ToString(b));
61 return writer;
62 }
63
64 public LogWriter& operator<<(LogWriter& writer, int i)
65 {
66 writer.Write(ToString(i));
67 return writer;
68 }
69
70 public LogWriter& operator<<(LogWriter& writer, uint u)
71 {
72 writer.Write(ToString(u));
73 return writer;
74 }
75
76 public LogWriter& operator<<(LogWriter& writer, long l)
77 {
78 writer.Write(ToString(l));
79 return writer;
80 }
81
82 public LogWriter& operator<<(LogWriter& writer, ulong u)
83 {
84 writer.Write(ToString(u));
85 return writer;
86 }
87
88 public LogWriter& operator<<(LogWriter& writer, const System.Endl& endl)
89 {
90 writer.WriteLine();
91 return writer;
92 }
93 }