markus / ConvertService / ServiceBase / Markus.Service.StationController / Controls / TraceTextSource.cs @ e6281033
이력 | 보기 | 이력해설 | 다운로드 (1.31 KB)
1 | 1ae729e4 | taeseongkim | using System; |
---|---|---|---|
2 | using System.Diagnostics; |
||
3 | |||
4 | a34f58f6 | taeseongkim | namespace Markus.Service.StationController.Controls |
5 | 1ae729e4 | taeseongkim | { |
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 | 65fbe3cb | taeseongkim | _eventType = eventType; |
27 | base.TraceEvent(eventCache, source, eventType, id, message); |
||
28 | 1ae729e4 | taeseongkim | } |
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 | } |