-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathSentryStructuredLoggerBenchmarks.cs
More file actions
59 lines (48 loc) · 1.31 KB
/
SentryStructuredLoggerBenchmarks.cs
File metadata and controls
59 lines (48 loc) · 1.31 KB
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
#nullable enable
using BenchmarkDotNet.Attributes;
using Sentry.Extensibility;
using Sentry.Internal;
using Sentry.Testing;
namespace Sentry.Benchmarks;
public class SentryStructuredLoggerBenchmarks
{
private Hub _hub = null!;
private SentryStructuredLogger _logger = null!;
private SentryLog? _lastLog;
[GlobalSetup]
public void Setup()
{
SentryOptions options = new()
{
Dsn = DsnSamples.ValidDsn,
EnableLogs = true,
};
options.SetBeforeSendLog((SentryLog log) =>
{
_lastLog = log;
return null;
});
MockClock clock = new(new DateTimeOffset(2025, 04, 22, 14, 51, 00, 789, TimeSpan.FromHours(2)));
_hub = new Hub(options, DisabledHub.Instance);
_logger = SentryStructuredLogger.Create(_hub, options, clock);
}
[Benchmark]
public void LogWithoutParameters()
{
_logger.LogInfo("Message Text");
}
[Benchmark]
public void LogWithParameters()
{
_logger.LogInfo("Template string with arguments: {0}, {1}, {2}, {3}", "string", true, 1, 2.2);
}
[GlobalCleanup]
public void Cleanup()
{
_hub.Dispose();
if (_lastLog is null)
{
throw new InvalidOperationException("Last Log is null");
}
}
}