/
DiagnosticEventObserver.cs
40 lines (34 loc) · 1.06 KB
/
DiagnosticEventObserver.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
using System;
using System.Collections.Generic;
namespace DiagnosticSourceDemo.Processors
{
public class DiagnosticEventObserver : IObserver<KeyValuePair<string, object>>
{
private readonly DiagnosticEventCollection _eventCollection;
public DiagnosticEventObserver(IDiagnosticProcessor diagnosticProcessor)
{
_eventCollection = new DiagnosticEventCollection(diagnosticProcessor);
}
public void OnCompleted()
{
// Method intentionally left empty.
}
public void OnError(Exception error)
{
// Method intentionally left empty.
}
public void OnNext(KeyValuePair<string, object> value)
{
var diagnosticEvent = _eventCollection.GetDiagnosticEvent(value.Key);
if (diagnosticEvent == null) return;
try
{
diagnosticEvent.Invoke(value.Value);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}