Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/platforms/dotnet/common/migration/v6-to-v7/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ The [Interactive 7.x Migration Guide](./interactive/) lets you check off complet

<Include name="migration/dotnet-v7/move-sdk-settings-out-of-the-log4net-appender" />

### Logging Integrations No Longer Report Startup Crashes

<Include name="migration/dotnet-v7/logging-integrations-no-longer-report-startup-crashes" />

## Logs and Metrics

### EnableLogs Is Removed from SentryOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Initialize Sentry with the call that matches your app:

`UseSentry` reads its settings from the `Sentry` section of `appsettings.json`. `SentrySdk.Init` only uses the options you set in code and environment variables such as `SENTRY_DSN`.

To also send crashes from before `UseSentry` starts Sentry, see [Logging Integrations No Longer Report Startup Crashes](#logging-integrations-no-longer-report-startup-crashes).

`UseSentry` also adds Sentry's own `ILogger` integration. If your app sends `ILogger` entries through Serilog, NLog or log4net as well, Sentry receives each entry twice unless only one of them sends it:

- **Serilog.** Add Serilog with `builder.Services.AddSerilog(...)` from `Serilog.Extensions.Hosting`, or with `builder.Host.UseSerilog(...)`. Both replace the app's `ILogger` factory, so each entry reaches Sentry once, through the sink. Don't use `builder.Logging.AddSerilog()` or `writeToProviders: true`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
id: logging-integrations-no-longer-report-startup-crashes
title: "Logging Integrations No Longer Report Startup Crashes"
phase: verify
category: behavior
severity: behavior-change
frameworks: all
platformCategory: all
order: 55
---

Apps that set the DSN on the Serilog sink, the NLog target or the log4net appender no longer send crashes that happen before `UseSentry` starts Sentry. In 6.x, the logging integration started Sentry itself, so a crash logged from `Main` was sent.

`UseSentry` starts Sentry when the host is built or, in ASP.NET Core, when the app starts running. To also send crashes from before then, call `SentrySdk.Init` at the top of `Main`, before you create the builder, keep `UseSentry` and capture the crash in a `catch`:

```csharp {filename:Program.cs}
using var sentry = SentrySdk.Init(options =>
{
options.Dsn = "___PUBLIC_DSN___";
});

try
{
var builder = WebApplication.CreateBuilder(args);
builder.UseSentry(options => options.Dsn = "___PUBLIC_DSN___");

var app = builder.Build();
app.Run();
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
throw;
}
```

If your `catch` already logs the crash, such as with Serilog's `Log.Fatal`, you can keep that instead of calling `CaptureException`.

`UseSentry` replaces the first initialization once it starts, and the two don't share options. The [Serilog](/platforms/dotnet/guides/serilog/#capturing-startup-crashes), [NLog](/platforms/dotnet/guides/nlog/#capturing-startup-crashes) and [log4net](/platforms/dotnet/guides/log4net/#capturing-startup-crashes) guides show the full setup.
Loading