Question, maybe a bug about sentry, serilog and setting dsn #2225
-
Hello, I’m running into a curious bug? with the configuration of sentry and serilog and setting the dsn. I’m using c#, dotnet core. I’m trying to setup sentry through startup.cs and failing. My program.cs: private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseConsoleLifetime(options => options.SuppressStatusMessages = true)
.UseSerilog()
//works
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseSentry("some valid sentry url"))
//should work but doesn't?
//.ConfigureWebHostDefaults(webBuilder => webBuilder.UseSentry())
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
} My startup.cs: var logConfiguration = new LoggerConfiguration();
logConfiguration.WriteTo.Sentry(options =>
{
options.Dsn = "Same valid sentry url";
options.DiagnosticLevel = SentryLevel.Error;
options.MinimumBreadcrumbLevel = LogEventLevel.Information;
options.MinimumEventLevel = LogEventLevel.Error;
});
var logger = logConfiguration.CreateLogger();
Log.Logger = logger; The issue is I would like to set the dsn in the startup.cs and not in the program.cs. However If I set it in the startup.cs and leave it empty in the program.cs nothing is logged to sentry. Any advice would be welcome. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The DSN needs to be set the first time that Sentry is initialized. For an ASP.NET Core app, that is when |
Beta Was this translation helpful? Give feedback.
The DSN needs to be set the first time that Sentry is initialized. For an ASP.NET Core app, that is when
UseSentry
is called from the web builder inprogram.cs
. You can instead useappsettings.json
if you like, but the DSN needs to be part of the Sentry configuration section, not the Sentry subsection of Serilog. See: #1800 (comment)