markus / ConvertService / ServiceBase / Markus.Service.StationController / Controls / TraceTextSource.cs @ 67df8dcd
이력 | 보기 | 이력해설 | 다운로드 (1.31 KB)
1 |
using System; |
---|---|
2 |
using System.Diagnostics; |
3 |
|
4 |
namespace Markus.Service.StationController.Controls |
5 |
{ |
6 |
class TraceTextSource : TraceListener |
7 |
{ |
8 |
public ITraceTextSink Sink { get; private set; } |
9 |
private bool _fail; |
10 |
private TraceEventType _eventType = TraceEventType.Information; |
11 |
|
12 |
public TraceTextSource(ITraceTextSink sink) |
13 |
{ |
14 |
Debug.Assert(sink != null); |
15 |
Sink = sink; |
16 |
} |
17 |
|
18 |
public override void Fail(string message) |
19 |
{ |
20 |
_fail = true; |
21 |
base.Fail(message); |
22 |
} |
23 |
|
24 |
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message) |
25 |
{ |
26 |
_eventType = eventType; |
27 |
base.TraceEvent(eventCache, source, eventType, id, message); |
28 |
} |
29 |
|
30 |
public override void Write(string message) |
31 |
{ |
32 |
if (IndentLevel > 0) |
33 |
message = message.PadLeft(IndentLevel + message.Length, '\t'); |
34 |
|
35 |
if (_fail) |
36 |
Sink.Fail(message); |
37 |
|
38 |
else |
39 |
Sink.Event(message, _eventType); |
40 |
|
41 |
_fail = false; |
42 |
_eventType = TraceEventType.Information; |
43 |
} |
44 |
|
45 |
public override void WriteLine(string message) |
46 |
{ |
47 |
Write(message + "\n"); |
48 |
} |
49 |
} |
50 |
} |