-
-
Notifications
You must be signed in to change notification settings - Fork 233
Expand file tree
/
Copy pathSentryStructuredLogger.cs
More file actions
126 lines (113 loc) · 9.05 KB
/
SentryStructuredLogger.cs
File metadata and controls
126 lines (113 loc) · 9.05 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using Sentry.Infrastructure;
using Sentry.Internal;
namespace Sentry;
/// <summary>
/// Creates and sends logs to Sentry.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
[Experimental(DiagnosticId.ExperimentalFeature)]
public abstract class SentryStructuredLogger
{
internal static SentryStructuredLogger Create(IHub hub, SentryOptions options, ISystemClock clock)
=> Create(hub, options, clock, 100, TimeSpan.FromSeconds(5));
internal static SentryStructuredLogger Create(IHub hub, SentryOptions options, ISystemClock clock, int batchCount, TimeSpan batchInterval)
{
return options.Experimental.EnableLogs
? new DefaultSentryStructuredLogger(hub, options, clock, batchCount, batchInterval)
: DisabledSentryStructuredLogger.Instance;
}
private protected SentryStructuredLogger()
{
}
/// <summary>
/// Buffers a <see href="https://develop.sentry.dev/sdk/telemetry/logs">Sentry Log</see> message
/// via the associated <see href="https://develop.sentry.dev/sdk/telemetry/spans/batch-processor">Batch Processor</see>.
/// </summary>
/// <param name="level">The severity level of the log.</param>
/// <param name="template">The parameterized template string.</param>
/// <param name="parameters">The parameters to the <paramref name="template"/> string.</param>
/// <param name="configureLog">A configuration callback. Will be removed in a future version.</param>
private protected abstract void CaptureLog(SentryLogLevel level, string template, object[]? parameters, Action<SentryLog>? configureLog);
/// <summary>
/// Buffers a <see href="https://develop.sentry.dev/sdk/telemetry/logs">Sentry Log</see> message
/// via the associated <see href="https://develop.sentry.dev/sdk/telemetry/spans/batch-processor">Batch Processor</see>.
/// </summary>
/// <param name="log">The log.</param>
protected internal abstract void CaptureLog(SentryLog log);
/// <summary>
/// Clears all buffers for this logger and causes any buffered logs to be sent by the underlying <see cref="ISentryClient"/>.
/// </summary>
protected internal abstract void Flush();
/// <summary>
/// Creates and sends a structured log to Sentry, with severity <see cref="SentryLogLevel.Trace"/>, when enabled and sampled.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <param name="template">A formattable <see langword="string"/>. When incompatible with the <paramref name="parameters"/>, the log will not be captured. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="parameters">The arguments to the <paramref name="template"/>. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="configureLog">A delegate to set attributes on the <see cref="SentryLog"/>. When the delegate throws an <see cref="Exception"/> during invocation, the log will not be captured.</param>
[Experimental(DiagnosticId.ExperimentalFeature)]
public void LogTrace(string template, object[]? parameters = null, Action<SentryLog>? configureLog = null)
{
CaptureLog(SentryLogLevel.Trace, template, parameters, configureLog);
}
/// <summary>
/// Creates and sends a structured log to Sentry, with severity <see cref="SentryLogLevel.Debug"/>, when enabled and sampled.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <param name="template">A formattable <see langword="string"/>. When incompatible with the <paramref name="parameters"/>, the log will not be captured. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="parameters">The arguments to the <paramref name="template"/>. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="configureLog">A delegate to set attributes on the <see cref="SentryLog"/>. When the delegate throws an <see cref="Exception"/> during invocation, the log will not be captured.</param>
[Experimental(DiagnosticId.ExperimentalFeature)]
public void LogDebug(string template, object[]? parameters = null, Action<SentryLog>? configureLog = null)
{
CaptureLog(SentryLogLevel.Debug, template, parameters, configureLog);
}
/// <summary>
/// Creates and sends a structured log to Sentry, with severity <see cref="SentryLogLevel.Info"/>, when enabled and sampled.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <param name="template">A formattable <see langword="string"/>. When incompatible with the <paramref name="parameters"/>, the log will not be captured. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="parameters">The arguments to the <paramref name="template"/>. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="configureLog">A delegate to set attributes on the <see cref="SentryLog"/>. When the delegate throws an <see cref="Exception"/> during invocation, the log will not be captured.</param>
[Experimental(DiagnosticId.ExperimentalFeature)]
public void LogInfo(string template, object[]? parameters = null, Action<SentryLog>? configureLog = null)
{
CaptureLog(SentryLogLevel.Info, template, parameters, configureLog);
}
/// <summary>
/// Creates and sends a structured log to Sentry, with severity <see cref="SentryLogLevel.Warning"/>, when enabled and sampled.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <param name="template">A formattable <see langword="string"/>. When incompatible with the <paramref name="parameters"/>, the log will not be captured. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="parameters">The arguments to the <paramref name="template"/>. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="configureLog">A delegate to set attributes on the <see cref="SentryLog"/>. When the delegate throws an <see cref="Exception"/> during invocation, the log will not be captured.</param>
[Experimental(DiagnosticId.ExperimentalFeature)]
public void LogWarning(string template, object[]? parameters = null, Action<SentryLog>? configureLog = null)
{
CaptureLog(SentryLogLevel.Warning, template, parameters, configureLog);
}
/// <summary>
/// Creates and sends a structured log to Sentry, with severity <see cref="SentryLogLevel.Error"/>, when enabled and sampled.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <param name="template">A formattable <see langword="string"/>. When incompatible with the <paramref name="parameters"/>, the log will not be captured. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="parameters">The arguments to the <paramref name="template"/>. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="configureLog">A delegate to set attributes on the <see cref="SentryLog"/>. When the delegate throws an <see cref="Exception"/> during invocation, the log will not be captured.</param>
[Experimental(DiagnosticId.ExperimentalFeature)]
public void LogError(string template, object[]? parameters = null, Action<SentryLog>? configureLog = null)
{
CaptureLog(SentryLogLevel.Error, template, parameters, configureLog);
}
/// <summary>
/// Creates and sends a structured log to Sentry, with severity <see cref="SentryLogLevel.Fatal"/>, when enabled and sampled.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <param name="template">A formattable <see langword="string"/>. When incompatible with the <paramref name="parameters"/>, the log will not be captured. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="parameters">The arguments to the <paramref name="template"/>. See <see href="https://learn.microsoft.com/dotnet/api/system.string.format">System.String.Format</see>.</param>
/// <param name="configureLog">A delegate to set attributes on the <see cref="SentryLog"/>. When the delegate throws an <see cref="Exception"/> during invocation, the log will not be captured.</param>
[Experimental(DiagnosticId.ExperimentalFeature)]
public void LogFatal(string template, object[]? parameters = null, Action<SentryLog>? configureLog = null)
{
CaptureLog(SentryLogLevel.Fatal, template, parameters, configureLog);
}
}