79552145

Date: 2025-04-03 06:31:20
Score: 1
Natty:
Report link

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;
       });
Reasons:
  • Blacklisted phrase (1): did not work
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Anders