-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextTraceListener.cs
48 lines (42 loc) · 1.39 KB
/
TextTraceListener.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Reactive.Subjects;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using ScriptCommander.Annotations;
namespace ScriptCommander
{
public class TextTraceListener : TraceListener, INotifyPropertyChanged
{
private readonly Subject<string> _textOut = new Subject<string>();
public IObservable<string> TextOut { get { return _textOut; } }
private string _trace = string.Empty;
public string Trace
{
get { return _trace; }
private set
{
if (value == _trace) return;
_trace = value;
OnPropertyChanged();
}
}
public override void Write(string message)
{
Trace += message;
Task.Factory.StartNew(() => _textOut.OnNext(message));
}
public override void WriteLine(string message)
{
Write(message + Environment.NewLine);
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}