-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
TestTelemetryProcessor.cs
47 lines (41 loc) · 1.46 KB
/
TestTelemetryProcessor.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
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cs_unittest
{
public class TestTelemetryProcessor: ITelemetryProcessor
{
private ITelemetryProcessor Next { get; set; }
public SynchronizedCollection<ExceptionTelemetry> Exceptions { get; private set; }
// Link processors to each other in a chain.
public TestTelemetryProcessor(ITelemetryProcessor next, SynchronizedCollection<ExceptionTelemetry> exceptions)
{
this.Next = next;
this.Exceptions = exceptions;
}
public void Process(ITelemetry item)
{
var tt = item as TraceTelemetry;
if (tt != null)
{
Console.WriteLine($"Trace: {tt.Message}");
foreach (var prop in tt.Properties)
Console.WriteLine($"\t{prop.Key}: {prop.Value}");
}
var et = item as ExceptionTelemetry;
if (et != null)
{
this.Exceptions.Add(et);
Console.WriteLine($"Exception: {et.Message}. {et.Exception.StackTrace}");
}
this.Next.Process(item);
}
}
}