This helped me to catch unhandled exceptions.
.UseSentry(options =>
{
options.SetBeforeSend((sentryEvent, hint) =>
{
if (sentryEvent?.SentryExceptions.FirstOrDefault()?.Mechanism.Handled == false)
{
return sentryEvent;
}
return null;
});
MinimumEventLevel is of type Microsoft.Extensions.Logging LogLevel not SentryLevel, I tried to set it to LogLevel.Critical but is not sure if it did help.
options.MinimumEventLevel = LogLevel.Critical;
The reason it did not work to set SentryLevel.Fatal was that the SetBeforeSend did not get the modified exception.
SentrySdk.ConfigureScope(scope =>
{
scope.Level = SentryLevel.Fatal;
});
SentrySdk.CaptureException(ex);
options.SetBeforeSend((sentryEvent, hint) =>
{
if (sentryEvent?.Level == SentryLevel.Fatal)
{
return sentryEvent;
}
return null;
});