annotate Implab/Diagnostics/LogChannel.cs @ 45:d10034588e38 interactive logger

initial work on interactive logger
author cin
date Thu, 17 Apr 2014 03:05:53 +0400
parents c2c043520724
children d9d794b61bb9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
1 using System;
313f708a50e9 improved log concept
cin
parents:
diff changeset
2 using System.Collections.Generic;
313f708a50e9 improved log concept
cin
parents:
diff changeset
3 using System.Linq;
313f708a50e9 improved log concept
cin
parents:
diff changeset
4 using System.Text;
313f708a50e9 improved log concept
cin
parents:
diff changeset
5
313f708a50e9 improved log concept
cin
parents:
diff changeset
6 namespace Implab.Diagnostics {
313f708a50e9 improved log concept
cin
parents:
diff changeset
7 public class LogChannel<TEvent> {
313f708a50e9 improved log concept
cin
parents:
diff changeset
8 static LogChannel<TEvent> _default = new LogChannel<TEvent>();
313f708a50e9 improved log concept
cin
parents:
diff changeset
9
313f708a50e9 improved log concept
cin
parents:
diff changeset
10 public static LogChannel<TEvent> Default {
313f708a50e9 improved log concept
cin
parents:
diff changeset
11 get {
313f708a50e9 improved log concept
cin
parents:
diff changeset
12 return _default;
313f708a50e9 improved log concept
cin
parents:
diff changeset
13 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
14 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
15
313f708a50e9 improved log concept
cin
parents:
diff changeset
16 public event EventHandler<ValueEventArgs<TEvent>> Events;
313f708a50e9 improved log concept
cin
parents:
diff changeset
17
313f708a50e9 improved log concept
cin
parents:
diff changeset
18 public void LogEvent(TEvent data) {
313f708a50e9 improved log concept
cin
parents:
diff changeset
19 var t = Events;
313f708a50e9 improved log concept
cin
parents:
diff changeset
20 if (t!= null)
313f708a50e9 improved log concept
cin
parents:
diff changeset
21 t(TraceContext.Current,new ValueEventArgs<TEvent>(data));
313f708a50e9 improved log concept
cin
parents:
diff changeset
22 }
37
c2c043520724 working version of diagnostics logging
cin
parents: 36
diff changeset
23
c2c043520724 working version of diagnostics logging
cin
parents: 36
diff changeset
24 public void LogEvent(TraceContext context,TEvent data) {
c2c043520724 working version of diagnostics logging
cin
parents: 36
diff changeset
25 var t = Events;
c2c043520724 working version of diagnostics logging
cin
parents: 36
diff changeset
26 if (t != null)
c2c043520724 working version of diagnostics logging
cin
parents: 36
diff changeset
27 t(context, new ValueEventArgs<TEvent>(data));
c2c043520724 working version of diagnostics logging
cin
parents: 36
diff changeset
28 }
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
29 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
30 }