.NETCore SentrySdk.CaptureMessage with Host.CreateDefaultBuilder

Hi, I’m having trouble using SentrySdk with AspNetCore.
looking examples/dotnet at master · getsentry/examples · GitHub but not find solution.

My configuration:

public static IHostBuilder CreateHostBuilder(string[] args)
        {
            var host = Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(web =>
                {
                    web.UseStartup<Startup>();
                    web.UseSentry();
                });
   return host;
        }

Sentry + Serilog works fine.

I want to use SentrySdk.CaptureMessage, but still have SentrySdk.IsEnabled to false.

Can I use SentrySdk in conjunction with HostBuilder.UseSentry?

Does SentrySdk need to be initialized separately, i.e. does it not automatically get configuration from appsettings.json?

Thanks for help.

The ASP.NET Core and Serilog integrations rely on the core SentrySdk infrastructure. So if you init via UseSentry or via SentrySdk.Init it works the same.
You should be able to capture log messages with logger.LogWarning or higher by default (or lower level if you set MinimumEventLevel). or SentrySdk.CaptureMessage.

Thanks for the answer.
I will take some time to find a problem … if I use Serilog to write logs to multiple files, eg each module a separate file. Then logging events from Serilog to Sentry works weird. Not all log sends to Sentry.

I will try to prepare a sample code and send it - maybe it’s Serilog fault not Sentry.

Simplification application of Serilog (one log per application) everything works fine.
Thanks for your time!

1 Like