1 | Namespace System
|
---|
2 | Namespace Diagnostics
|
---|
3 |
|
---|
4 | ' リスナ
|
---|
5 | Class TraceListener
|
---|
6 | indentLevel As Long
|
---|
7 | indentSize As Long
|
---|
8 |
|
---|
9 | Protected
|
---|
10 | Function GetIndentString() As String
|
---|
11 | Dim i As Long
|
---|
12 |
|
---|
13 | Dim IndentStr = ""
|
---|
14 | For i = 0 To ELM( indentSize )
|
---|
15 | IndentStr = IndentStr + " "
|
---|
16 | Next
|
---|
17 |
|
---|
18 | Dim ResultStr = ""
|
---|
19 | For i = 0 To ELM( indentLevel )
|
---|
20 | ResultStr = ResultStr + IndentStr
|
---|
21 | Next
|
---|
22 |
|
---|
23 | Return ResultStr
|
---|
24 | End Function
|
---|
25 |
|
---|
26 | Public
|
---|
27 | Sub TraceListener()
|
---|
28 | indentLevel = 0
|
---|
29 | indentSize = 4
|
---|
30 | End Sub
|
---|
31 |
|
---|
32 | ' コピーコンストラクタ
|
---|
33 | Sub TraceListener( ByRef listener As TraceListener )
|
---|
34 | indentLevel = listener.indentLevel
|
---|
35 | indentSize = listener.indentSize
|
---|
36 | End Sub
|
---|
37 |
|
---|
38 |
|
---|
39 | '----------------------------------------------------------------
|
---|
40 | ' パブリック メソッド
|
---|
41 | '----------------------------------------------------------------
|
---|
42 |
|
---|
43 | Virtual Sub Write( message As String )
|
---|
44 | '派生クラスで実装 (基底では何もしない)
|
---|
45 | End Sub
|
---|
46 | Virtual Sub Write( value As Object )
|
---|
47 | Write( value.ToString() )
|
---|
48 | End Sub
|
---|
49 | Virtual Sub Write( value As Object, category As String )
|
---|
50 | Write( category + ": " + value.ToString() )
|
---|
51 | End Sub
|
---|
52 | Virtual Sub Write( message As String, category As String )
|
---|
53 | Write( category + ": " + message )
|
---|
54 | End Sub
|
---|
55 |
|
---|
56 | Virtual Sub WriteLine( message As String )
|
---|
57 | '派生クラスで実装 (基底では何もしない)
|
---|
58 | End Sub
|
---|
59 | Virtual Sub WriteLine( value As Object )
|
---|
60 | WriteLine( value.ToString() )
|
---|
61 | End Sub
|
---|
62 | Virtual Sub WriteLine( value As Object, category As String )
|
---|
63 | WriteLine( category + ": " + value.ToString() )
|
---|
64 | End Sub
|
---|
65 | Virtual Sub WriteLine( message As String, category As String )
|
---|
66 | WriteLine( category + ": " + message )
|
---|
67 | End Sub
|
---|
68 |
|
---|
69 | ' 条件をもとに文字列を出力
|
---|
70 | Sub WriteIf( condition As Boolean, value As Object )
|
---|
71 | If condition Then
|
---|
72 | Write( value )
|
---|
73 | End If
|
---|
74 | End Sub
|
---|
75 | Sub WriteIf( condition As Boolean, message As String )
|
---|
76 | If condition Then
|
---|
77 | Write( message )
|
---|
78 | End If
|
---|
79 | End Sub
|
---|
80 | Sub WriteIf( condition As Boolean, value As Object, category As String )
|
---|
81 | If condition Then
|
---|
82 | Write( value, category )
|
---|
83 | End If
|
---|
84 | End Sub
|
---|
85 | Sub WriteIf( condition As Boolean, message As String, category As String )
|
---|
86 | If condition Then
|
---|
87 | Write( message, category )
|
---|
88 | End If
|
---|
89 | End Sub
|
---|
90 |
|
---|
91 | ' 条件をもとに文字列を出力
|
---|
92 | Sub WriteLineIf( condition As Boolean, value As Object )
|
---|
93 | If condition Then
|
---|
94 | WriteLine( value )
|
---|
95 | End If
|
---|
96 | End Sub
|
---|
97 | Sub WriteLineIf( condition As Boolean, message As String )
|
---|
98 | If condition Then
|
---|
99 | WriteLine( message )
|
---|
100 | End If
|
---|
101 | End Sub
|
---|
102 | Sub WriteLineIf( condition As Boolean, value As Object, category As String )
|
---|
103 | If condition Then
|
---|
104 | WriteLine( value, category )
|
---|
105 | End If
|
---|
106 | End Sub
|
---|
107 | Sub WriteLineIf( condition As Boolean, message As String, category As String )
|
---|
108 | If condition Then
|
---|
109 | WriteLine( message, category )
|
---|
110 | End If
|
---|
111 | End Sub
|
---|
112 |
|
---|
113 |
|
---|
114 | '----------------------------------------------------------------
|
---|
115 | ' パブリック プロパティ
|
---|
116 | '----------------------------------------------------------------
|
---|
117 |
|
---|
118 | ' IndentLevelプロパティ
|
---|
119 | Function IndentLevel() As Long
|
---|
120 | Return indentLevel
|
---|
121 | End Function
|
---|
122 | Sub IndentLevel( indentLevel As Long )
|
---|
123 | This.indentLevel = indentLevel
|
---|
124 | End Sub
|
---|
125 |
|
---|
126 | ' IndentSizeプロパティ
|
---|
127 | Function IndentSize() As Long
|
---|
128 | Return indentSize
|
---|
129 | End Function
|
---|
130 | Sub IndentSize( size As Long )
|
---|
131 | indentSize = size
|
---|
132 | End Sub
|
---|
133 | End Class
|
---|
134 |
|
---|
135 | ' デフォルトリスナ(デバッガビューへの出力)
|
---|
136 | Class DefaultTraceListener
|
---|
137 | Inherits TraceListener
|
---|
138 | Public
|
---|
139 |
|
---|
140 | Override Sub Write( message As String )
|
---|
141 | ' デバッグビューへ出力
|
---|
142 | Dim tempStr = GetIndentString() + message
|
---|
143 | OutputDebugString( tempStr )
|
---|
144 |
|
---|
145 | ' デバッグログへ書き込む
|
---|
146 | ' TODO: 実装
|
---|
147 | End Sub
|
---|
148 |
|
---|
149 | Override Sub WriteLine( message As String )
|
---|
150 | Write( GetIndentString() + message + Ex"\r\n" )
|
---|
151 | End Sub
|
---|
152 | End Class
|
---|
153 |
|
---|
154 | End Namespace
|
---|
155 | End Namespace
|
---|