-
Notifications
You must be signed in to change notification settings - Fork 91
/
RaygunBreadcrumbs.cs
88 lines (77 loc) · 2.06 KB
/
RaygunBreadcrumbs.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace Mindscape.Raygun4Net.Breadcrumbs
{
internal class RaygunBreadcrumbs : IEnumerable<RaygunBreadcrumb>
{
private readonly IRaygunBreadcrumbStorage _storage;
public RaygunBreadcrumbs(IRaygunBreadcrumbStorage storage)
{
_storage = storage;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public IEnumerator<RaygunBreadcrumb> GetEnumerator()
{
return _storage.GetEnumerator();
}
public void Record(RaygunBreadcrumb crumb)
{
if (RaygunSettings.Settings.BreadcrumbsLocationRecordingEnabled)
{
try
{
for(int i = 1; i <= 3; i++)
{
PopulateLocation(crumb, i);
if (crumb.ClassName == null || !crumb.ClassName.StartsWith("Mindscape.Raygun4Net"))
{
break;
}
}
}
catch (Exception)
{
if (RaygunSettings.Settings.ThrowOnError)
{
throw;
}
}
}
if (ShouldRecord(crumb))
{
_storage.Store(crumb);
}
}
private void PopulateLocation(RaygunBreadcrumb crumb, int stackTraceFrame)
{
var frame = new StackFrame(stackTraceFrame);
var method = frame.GetMethod();
crumb.ClassName = method.ReflectedType == null ? null : method.ReflectedType.FullName;
crumb.MethodName = method.Name;
crumb.LineNumber = frame.GetFileLineNumber();
if (crumb.MethodName.Contains("<"))
{
var unmangledName = new Regex(@"<(\w+)>").Match(crumb.MethodName).Groups[1].Value;
crumb.MethodName = unmangledName;
}
if (crumb.LineNumber == 0)
{
crumb.LineNumber = null;
}
}
public void Clear()
{
_storage.Clear();
}
private bool ShouldRecord(RaygunBreadcrumb crumb)
{
return crumb.Level >= RaygunSettings.Settings.BreadcrumbsLevel;
}
}
}