Skip to content

Commit 1bc3a6f

Browse files
committed
feat(logs): Sentry.AspNetCore
1 parent 8d03449 commit 1bc3a6f

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

samples/Sentry.Samples.AspNetCore.Basic/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// Log debug information about the Sentry SDK
1313
options.Debug = true;
1414
#endif
15+
16+
// This option enables the (experimental) Sentry Logs.
17+
options.EnableLogs = true;
1518
});
1619

1720
var app = builder.Build();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.Extensions.Logging;
2+
using Microsoft.Extensions.Options;
3+
using Sentry.Extensions.Logging;
4+
5+
namespace Sentry.AspNetCore;
6+
7+
/// <summary>
8+
/// Structured Logger Provider for Sentry.
9+
/// </summary>
10+
[ProviderAlias("SentryLogs")]
11+
[Experimental(Infrastructure.DiagnosticId.ExperimentalFeature)]
12+
internal sealed class SentryAspNetCoreStructuredLoggerProvider : SentryStructuredLoggerProvider
13+
{
14+
public SentryAspNetCoreStructuredLoggerProvider(IOptions<SentryAspNetCoreOptions> options, IHub hub)
15+
: base(options, hub)
16+
{
17+
}
18+
}

src/Sentry.AspNetCore/SentryWebHostBuilderExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,15 @@ public static IWebHostBuilder UseSentry(
9393
_ = logging.Services
9494
.AddSingleton<IConfigureOptions<SentryAspNetCoreOptions>, SentryAspNetCoreOptionsSetup>();
9595
_ = logging.Services.AddSingleton<ILoggerProvider, SentryAspNetCoreLoggerProvider>();
96+
_ = logging.Services.AddSingleton<ILoggerProvider, SentryAspNetCoreStructuredLoggerProvider>();
9697

9798
_ = logging.AddFilter<SentryAspNetCoreLoggerProvider>(
9899
"Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware",
99100
LogLevel.None);
101+
_ = logging.AddFilter<SentryAspNetCoreStructuredLoggerProvider>(static (string? categoryName, LogLevel logLevel) =>
102+
{
103+
return categoryName is null || !categoryName.StartsWith("Sentry");
104+
});
100105

101106
var sentryBuilder = logging.Services.AddSentry();
102107
configureSentry?.Invoke(context, sentryBuilder);

src/Sentry.Extensions.Logging/SentryStructuredLoggerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Sentry.Extensions.Logging;
88
/// </summary>
99
[ProviderAlias("SentryLogs")]
1010
[Experimental(Infrastructure.DiagnosticId.ExperimentalFeature)]
11-
internal sealed class SentryStructuredLoggerProvider : ILoggerProvider
11+
internal class SentryStructuredLoggerProvider : ILoggerProvider
1212
{
1313
private readonly IOptions<SentryLoggingOptions> _options;
1414
private readonly IHub _hub;

0 commit comments

Comments
 (0)