|
1 | 1 | using Microsoft.Extensions.Logging; |
2 | 2 | using Sentry.Extensions.Logging; |
3 | 3 |
|
4 | | -using var loggerFactory = LoggerFactory.Create(builder => |
| 4 | +// Initialise the Sentry SDK. The logging integration added below only forwards log messages to Sentry. |
| 5 | +using var sentry = SentrySdk.Init(options => |
5 | 6 | { |
6 | | - builder.AddConsole(); |
7 | | - builder.AddSentry(options => |
8 | | - { |
9 | 7 | #if !SENTRY_DSN_DEFINED_IN_ENV |
10 | | - // A DSN is required. You can set here in code, or you can set it in the SENTRY_DSN environment variable. |
11 | | - // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ |
12 | | - options.Dsn = SamplesShared.Dsn; |
| 8 | + // A DSN is required. You can set here in code, or you can set it in the SENTRY_DSN environment variable. |
| 9 | + // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ |
| 10 | + options.Dsn = SamplesShared.Dsn; |
13 | 11 | #endif |
14 | 12 |
|
15 | | - // Set to true to SDK debugging to see the internal messages through the logging library. |
16 | | - options.Debug = false; |
17 | | - // Configure the level of Sentry internal logging |
18 | | - options.DiagnosticLevel = SentryLevel.Debug; |
| 13 | + // Set to true to SDK debugging to see the internal messages through the logging library. |
| 14 | + options.Debug = false; |
| 15 | + // Configure the level of Sentry internal logging |
| 16 | + options.DiagnosticLevel = SentryLevel.Debug; |
19 | 17 |
|
20 | | - options.MaxBreadcrumbs = 150; // Increasing from default 100 |
21 | | - options.Release = "e386dfd"; // If not set here, SDK looks for it on main assembly's AssemblyInformationalVersion and AssemblyVersion |
| 18 | + options.MaxBreadcrumbs = 150; // Increasing from default 100 |
| 19 | + options.Release = "e386dfd"; // If not set here, SDK looks for it on main assembly's AssemblyInformationalVersion and AssemblyVersion |
| 20 | + |
| 21 | + options.SetBeforeSendLog(static log => |
| 22 | + { |
| 23 | + log.SetAttribute("attribute-key", "attribute-value"); |
| 24 | + return log; |
| 25 | + }); |
| 26 | +}); |
22 | 27 |
|
| 28 | +using var loggerFactory = LoggerFactory.Create(builder => |
| 29 | +{ |
| 30 | + builder.AddConsole(); |
| 31 | + builder.AddSentry(options => |
| 32 | + { |
23 | 33 | // Optionally configure options: The default values are: |
24 | 34 | options.MinimumBreadcrumbLevel = LogLevel.Information; // It requires at least this level to store breadcrumb |
25 | 35 | options.MinimumEventLevel = LogLevel.Error; // This level or above will result in event sent to Sentry |
26 | 36 |
|
27 | | - options.SetBeforeSendLog(static log => |
28 | | - { |
29 | | - log.SetAttribute("attribute-key", "attribute-value"); |
30 | | - return log; |
31 | | - }); |
32 | | - |
33 | 37 | // Don't keep as a breadcrumb or send events for messages of level less than Critical with exception of type DivideByZeroException |
34 | 38 | options.AddLogEntryFilter((_, level, _, exception) => level < LogLevel.Critical && exception is DivideByZeroException); |
35 | 39 |
|
|
86 | 90 | Dependency.Work("8 - This unhandled exception is captured and includes Scope (A, B) and crumbs: (2, 4, 5) and event (3) "); |
87 | 91 | } |
88 | 92 |
|
89 | | -// Disposing the LoggerFactory will close the SDK since it was initialized through |
90 | | -// the integration while calling .Init() |
91 | 93 |
|
92 | 94 | internal static class Dependency |
93 | 95 | { |
|
0 commit comments