[246] | 1 | Namespace System
|
---|
| 2 | Namespace Diagnostics
|
---|
[58] | 3 |
|
---|
[246] | 4 | ' リスナ
|
---|
| 5 | Class TraceListener
|
---|
| 6 | indentLevel As Long
|
---|
| 7 | indentSize As Long
|
---|
[58] | 8 |
|
---|
[246] | 9 | Protected
|
---|
| 10 | Function GetIndentString() As String
|
---|
| 11 | Dim i As Long
|
---|
[58] | 12 |
|
---|
[246] | 13 | Dim IndentStr = ""
|
---|
| 14 | For i = 0 To ELM( indentSize )
|
---|
| 15 | IndentStr = IndentStr + " "
|
---|
| 16 | Next
|
---|
[58] | 17 |
|
---|
[246] | 18 | Dim ResultStr = ""
|
---|
| 19 | For i = 0 To ELM( indentLevel )
|
---|
| 20 | ResultStr = ResultStr + IndentStr
|
---|
| 21 | Next
|
---|
[58] | 22 |
|
---|
[246] | 23 | Return ResultStr
|
---|
| 24 | End Function
|
---|
[58] | 25 |
|
---|
[246] | 26 | Public
|
---|
| 27 | Sub TraceListener()
|
---|
| 28 | indentLevel = 0
|
---|
| 29 | indentSize = 4
|
---|
| 30 | End Sub
|
---|
[58] | 31 |
|
---|
[246] | 32 | ' コピーコンストラクタ
|
---|
| 33 | Sub TraceListener( ByRef listener As TraceListener )
|
---|
| 34 | indentLevel = listener.indentLevel
|
---|
| 35 | indentSize = listener.indentSize
|
---|
| 36 | End Sub
|
---|
[58] | 37 |
|
---|
| 38 |
|
---|
[246] | 39 | '----------------------------------------------------------------
|
---|
| 40 | ' パブリック コンストラクタ
|
---|
| 41 | '----------------------------------------------------------------
|
---|
[58] | 42 |
|
---|
[246] | 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
|
---|
[58] | 55 |
|
---|
[246] | 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
|
---|
[58] | 68 |
|
---|
[290] | 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
|
---|
[58] | 90 |
|
---|
[290] | 91 |
|
---|
[246] | 92 | '----------------------------------------------------------------
|
---|
| 93 | ' パブリック プロパティ
|
---|
| 94 | '----------------------------------------------------------------
|
---|
[58] | 95 |
|
---|
[246] | 96 | ' IndentLevelプロパティ
|
---|
| 97 | Function IndentLevel() As Long
|
---|
| 98 | Return indentLevel
|
---|
| 99 | End Function
|
---|
| 100 | Sub IndentLevel( indentLevel As Long )
|
---|
| 101 | This.indentLevel = indentLevel
|
---|
| 102 | End Sub
|
---|
[58] | 103 |
|
---|
[246] | 104 | ' IndentSizeプロパティ
|
---|
| 105 | Function IndentSize() As Long
|
---|
| 106 | Return indentSize
|
---|
| 107 | End Function
|
---|
| 108 | Sub IndentSize( size As Long )
|
---|
| 109 | indentSize = size
|
---|
| 110 | End Sub
|
---|
| 111 | End Class
|
---|
[58] | 112 |
|
---|
[246] | 113 | ' デフォルトリスナ(デバッガビューへの出力)
|
---|
| 114 | Class DefaultTraceListener
|
---|
| 115 | Inherits TraceListener
|
---|
| 116 | Public
|
---|
[58] | 117 |
|
---|
[246] | 118 | Override Sub Write( message As String )
|
---|
| 119 | ' デバッグビューへ出力
|
---|
| 120 | Dim tempStr = GetIndentString() + message
|
---|
| 121 | OutputDebugString( tempStr )
|
---|
[58] | 122 |
|
---|
[246] | 123 | ' デバッグログへ書き込む
|
---|
| 124 | ' TODO: 実装
|
---|
| 125 | End Sub
|
---|
[58] | 126 |
|
---|
[246] | 127 | Override Sub WriteLine( message As String )
|
---|
| 128 | Write( GetIndentString() + message + Ex"\r\n" )
|
---|
| 129 | End Sub
|
---|
| 130 | End Class
|
---|
| 131 |
|
---|
| 132 | End Namespace
|
---|
| 133 | End Namespace
|
---|