Closed jeffvannijlen closed 3 years ago
Sentry's SDK is designed to be initialized only once for the lifetime of the app.
You can hold the reference to the disposable that Init
returns to call only when the app starts,
On a console app, the easiest way is to:
Main() {
using (SentrySdk.Init(..)) {
// App code here
}
}
You need to dispose it because that makes sure the SDK attempts to flush out queued events. Otherwise the app might close while your errors are still queued up for submission
If you're using Microsoft.Extensions.Logging
you can follow: https://github.com/getsentry/sentry-dotnet/blob/master/samples/Sentry.Samples.ME.Logging/Program.cs#L12
There are more samples in that directory
Please mark the type framework used:
Please mark the type of the runtime used:
[ ] .NET Framework
[ ] Mono
[X] .NET Core
Version: 2.2
Please mark the NuGet packages used:
[X] Sentry
[ ] Sentry.Serilog
[ ] Sentry.NLog
[ ] Sentry.Log4Net
[ ] Sentry.Extensions.Logging
[X] Sentry.AspNetCore
Version: 2.1.1
Hi,
We are trying to create a .netCore 2.2 Console app to Track Exceptions. However I was wondering if it's possible to do this without adding SentrySdk.Init() around every single statement.
Are there any issues doing the init once for the entire application lifetime? Is it safe if it will never be disposed?
Another question, is
SentrySdk.Init(dsn);
the only way to initialize this? I already tried usingSentrySdk.Init(options => ctx.Configuration.GetSection("Sentry").Bind(options));
but this doesn't seem to work.Or is there a better way to do this?
Thanks in advance!
Best regards
Jeff Van Nijlen