diff --git a/CHANGELOG.md b/CHANGELOG.md index e7cf9a2409..8a0034aa14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,18 +17,19 @@ without native/platform specific bindings and SDKs. See [this ticket for more de API Changes: - IHasMeasurements was removed. Use ISpanData instead. ([#2659](https://github.com/getsentry/sentry-dotnet/pull/2659)) -- If `null` has been supplied as DSN when initializing Sentry, and ArgumentNullException is now thrown ([#2655](https://github.com/getsentry/sentry-dotnet/pull/2655)) +- If `null` has been supplied as DSN when initializing Sentry, and ArgumentNullException is now thrown. ([#2655](https://github.com/getsentry/sentry-dotnet/pull/2655)) - IHasBreadcrumbs was removed. Use IEventLike instead. ([#2670](https://github.com/getsentry/sentry-dotnet/pull/2670)) - ISpanContext was removed. Use ITraceContext instead. ([#2668](https://github.com/getsentry/sentry-dotnet/pull/2668)) - Removed IHasTransactionNameSource. Use ITransactionContext instead. ([#2654](https://github.com/getsentry/sentry-dotnet/pull/2654)) -- Adding `Distribution` to `IEventLike` ([#2660](https://github.com/getsentry/sentry-dotnet/pull/2660)) -- Upgraded to NLog version 5 ([#2697](https://github.com/getsentry/sentry-dotnet/pull/2697)) +- Adding `Distribution` to `IEventLike`. ([#2660](https://github.com/getsentry/sentry-dotnet/pull/2660)) +- Upgraded to NLog version 5. ([#2697](https://github.com/getsentry/sentry-dotnet/pull/2697)) - Removed unused `StackFrame.InstructionOffset`. ([#2691](https://github.com/getsentry/sentry-dotnet/pull/2691)) - Change `StackFrame`'s `ImageAddress`, `InstructionAddress` and `FunctionId` to `long?`. ([#2691](https://github.com/getsentry/sentry-dotnet/pull/2691)) -- Enable `CaptureFailedRequests` by default ([2688](https://github.com/getsentry/sentry-dotnet/pull/2688)) +- Enable `CaptureFailedRequests` by default. ([2688](https://github.com/getsentry/sentry-dotnet/pull/2688)) - Additional constructors removed from `TransactionTracer`. ([#2694](https://github.com/getsentry/sentry-dotnet/pull/2694)) -- Removed the `Scope.Platform` property as it was never applied ([#2695](https://github.com/getsentry/sentry-dotnet/pull/2695)) +- Removed the `Scope.Platform` property as it was never applied. ([#2695](https://github.com/getsentry/sentry-dotnet/pull/2695)) - Reordered parameters for ther TransactionContext and SpanContext constructors. If you're constructing instances of these classes, you will need to adjust the order in which you pass parameters to these. ([#2696](https://github.com/getsentry/sentry-dotnet/pull/2696)) +- The `DiagnosticLogger` signature for `LogError` and `LogFatal` changed to take the `exception` as the first parameter. That way it does no longer get mixed up with the TArgs. The `DiagnosticLogger` now also received an overload for `LogError` and `LogFatal` that accepts a message only. ([#2715](https://github.com/getsentry/sentry-dotnet/pull/2715)) ## Unreleased diff --git a/src/Sentry.AspNet/HttpContextExtensions.cs b/src/Sentry.AspNet/HttpContextExtensions.cs index 6d0466caa1..c3e642cffd 100644 --- a/src/Sentry.AspNet/HttpContextExtensions.cs +++ b/src/Sentry.AspNet/HttpContextExtensions.cs @@ -26,7 +26,7 @@ public static class HttpContextExtensions } catch (Exception ex) { - options?.LogError("Invalid Sentry trace header '{0}'.", ex, value); + options?.LogError(ex, "Invalid Sentry trace header '{0}'.", value); return null; } } @@ -50,7 +50,7 @@ public static class HttpContextExtensions } catch (Exception ex) { - options?.LogError("Invalid baggage header '{0}'.", ex, value); + options?.LogError(ex, "Invalid baggage header '{0}'.", value); return null; } } diff --git a/src/Sentry.AspNetCore/Extensions/HttpContextExtensions.cs b/src/Sentry.AspNetCore/Extensions/HttpContextExtensions.cs index 8f51a8576a..63b15b6a30 100644 --- a/src/Sentry.AspNetCore/Extensions/HttpContextExtensions.cs +++ b/src/Sentry.AspNetCore/Extensions/HttpContextExtensions.cs @@ -64,7 +64,7 @@ internal static class HttpContextExtensions } catch (Exception ex) { - options?.LogError("Invalid Sentry trace header '{0}'.", ex, value); + options?.LogError(ex, "Invalid Sentry trace header '{0}'.", value); return null; } } @@ -88,7 +88,7 @@ internal static class HttpContextExtensions } catch (Exception ex) { - options?.LogError("Invalid baggage header '{0}'.", ex, value); + options?.LogError(ex, "Invalid baggage header '{0}'.", value); return null; } } diff --git a/src/Sentry.AspNetCore/ScopeExtensions.cs b/src/Sentry.AspNetCore/ScopeExtensions.cs index 44eecf786c..252dba06e6 100644 --- a/src/Sentry.AspNetCore/ScopeExtensions.cs +++ b/src/Sentry.AspNetCore/ScopeExtensions.cs @@ -64,7 +64,7 @@ public static void Populate(this Scope scope, HttpContext context, SentryAspNetC } catch (Exception e) { - options.LogError("Failed to extract body.", e); + options.LogError(e, "Failed to extract body."); } SetEnv(scope, context, options); diff --git a/src/Sentry.AspNetCore/SentryTracingMiddleware.cs b/src/Sentry.AspNetCore/SentryTracingMiddleware.cs index 4ee4532b1d..be5a15bdcc 100644 --- a/src/Sentry.AspNetCore/SentryTracingMiddleware.cs +++ b/src/Sentry.AspNetCore/SentryTracingMiddleware.cs @@ -90,7 +90,7 @@ internal class SentryTracingMiddleware } catch (Exception ex) { - _options.LogError("Failed to start transaction.", ex); + _options.LogError(ex, "Failed to start transaction."); return null; } } diff --git a/src/Sentry.Azure.Functions.Worker/HttpRequestDataExtensions.cs b/src/Sentry.Azure.Functions.Worker/HttpRequestDataExtensions.cs index 168dad89cf..194e8dcd6f 100644 --- a/src/Sentry.Azure.Functions.Worker/HttpRequestDataExtensions.cs +++ b/src/Sentry.Azure.Functions.Worker/HttpRequestDataExtensions.cs @@ -25,7 +25,7 @@ internal static class HttpRequestDataExtensions } catch (Exception ex) { - logger?.LogError("Invalid Sentry trace header '{0}'.", ex, traceHeaderValue); + logger?.LogError(ex, "Invalid Sentry trace header '{0}'.", traceHeaderValue); return null; } } @@ -53,7 +53,7 @@ internal static class HttpRequestDataExtensions } catch (Exception ex) { - logger?.LogError("Invalid baggage header '{0}'.", ex, baggageValue); + logger?.LogError(ex, "Invalid baggage header '{0}'.", baggageValue); return null; } } diff --git a/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentryEFCoreListener.cs b/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentryEFCoreListener.cs index 626c5a6f7c..2ce93bb10f 100644 --- a/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentryEFCoreListener.cs +++ b/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentryEFCoreListener.cs @@ -88,7 +88,7 @@ public void OnNext(KeyValuePair value) } catch (Exception ex) { - _options.LogError("Failed to intercept EF Core event.", ex); + _options.LogError(ex, "Failed to intercept EF Core event."); } } } diff --git a/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentrySqlListener.cs b/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentrySqlListener.cs index 6ad3a6dce2..d2e0acf5fe 100644 --- a/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentrySqlListener.cs +++ b/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentrySqlListener.cs @@ -244,7 +244,7 @@ public void OnNext(KeyValuePair kvp) } catch (Exception ex) { - _options.LogError("Failed to intercept SQL event.", ex); + _options.LogError(ex, "Failed to intercept SQL event."); } } diff --git a/src/Sentry.EntityFramework/SentryOptionsExtensions.cs b/src/Sentry.EntityFramework/SentryOptionsExtensions.cs index e76c670444..c7677914a5 100644 --- a/src/Sentry.EntityFramework/SentryOptionsExtensions.cs +++ b/src/Sentry.EntityFramework/SentryOptionsExtensions.cs @@ -28,7 +28,7 @@ public static SentryOptions AddEntityFramework(this SentryOptions sentryOptions) catch (Exception e) { sentryOptions.DiagnosticLogger? - .LogError("Failed to configure EF breadcrumbs. Make sure to init Sentry before EF.", e); + .LogError(e, "Failed to configure EF breadcrumbs. Make sure to init Sentry before EF."); } dbIntegration = new DbInterceptionIntegration(); diff --git a/src/Sentry.Maui/Internal/MauiDeviceData.cs b/src/Sentry.Maui/Internal/MauiDeviceData.cs index 377feccff3..71a7fdd78a 100644 --- a/src/Sentry.Maui/Internal/MauiDeviceData.cs +++ b/src/Sentry.Maui/Internal/MauiDeviceData.cs @@ -112,7 +112,7 @@ public static void ApplyMauiDeviceData(this Device device, IDiagnosticLogger? lo catch (Exception ex) { // Log, but swallow the exception so we can continue sending events - logger?.LogError("Error getting MAUI device information.", ex); + logger?.LogError(ex, "Error getting MAUI device information."); } } } diff --git a/src/Sentry.Maui/Internal/MauiEventsBinder.cs b/src/Sentry.Maui/Internal/MauiEventsBinder.cs index a51398b8dc..9e3a095b18 100644 --- a/src/Sentry.Maui/Internal/MauiEventsBinder.cs +++ b/src/Sentry.Maui/Internal/MauiEventsBinder.cs @@ -143,7 +143,7 @@ public void BindReflectedEvents(BindableObject bindableObject, bool includeExpli catch (Exception ex) { // Don't throw if we can't bind the event handler - _options.DiagnosticLogger?.LogError("Couldn't bind to {0}.{1}", ex, type.Name, eventInfo.Name); + _options.DiagnosticLogger?.LogError(ex, "Couldn't bind to {0}.{1}", type.Name, eventInfo.Name); } } } diff --git a/src/Sentry.Maui/Internal/MauiOsData.cs b/src/Sentry.Maui/Internal/MauiOsData.cs index e49759ee5f..642444b799 100644 --- a/src/Sentry.Maui/Internal/MauiOsData.cs +++ b/src/Sentry.Maui/Internal/MauiOsData.cs @@ -40,7 +40,7 @@ public static void ApplyMauiOsData(this OperatingSystem os, IDiagnosticLogger? l catch (Exception ex) { // Log, but swallow the exception so we can continue sending events - logger?.LogError("Error getting MAUI OS information.", ex); + logger?.LogError(ex, "Error getting MAUI OS information."); } } } diff --git a/src/Sentry.NLog/SentryTarget.cs b/src/Sentry.NLog/SentryTarget.cs index 233dc46502..8445bef42b 100644 --- a/src/Sentry.NLog/SentryTarget.cs +++ b/src/Sentry.NLog/SentryTarget.cs @@ -303,7 +303,7 @@ protected override void Write(LogEventInfo logEvent) } catch (Exception exception) { - Options.DiagnosticLogger?.LogError("Failed to write log event", exception); + Options.DiagnosticLogger?.LogError(exception, "Failed to write log event"); throw; } finally diff --git a/src/Sentry.Profiling/SamplingTransactionProfilerFactory.cs b/src/Sentry.Profiling/SamplingTransactionProfilerFactory.cs index c2fa66cd92..b00faa543e 100644 --- a/src/Sentry.Profiling/SamplingTransactionProfilerFactory.cs +++ b/src/Sentry.Profiling/SamplingTransactionProfilerFactory.cs @@ -51,7 +51,7 @@ private SamplingTransactionProfilerFactory(SentryOptions options, SampleProfiler } catch (Exception e) { - _options.LogError("Failed to start a profiler session.", e); + _options.LogError(e, "Failed to start a profiler session."); _inProgress = FALSE; } } diff --git a/src/Sentry/Extensibility/DiagnosticLoggerExtensions.cs b/src/Sentry/Extensibility/DiagnosticLoggerExtensions.cs index ae157c4b15..579364db9f 100644 --- a/src/Sentry/Extensibility/DiagnosticLoggerExtensions.cs +++ b/src/Sentry/Extensibility/DiagnosticLoggerExtensions.cs @@ -211,8 +211,15 @@ public static class DiagnosticLoggerExtensions /// public static void LogError( this IDiagnosticLogger logger, - string message, - Exception? exception = null) + string message) + => logger.LogIfEnabled(SentryLevel.Error, null, message); + + /// + /// Log an exception with an error message. + /// + public static void LogError(this IDiagnosticLogger logger, + Exception exception, + string message) => logger.LogIfEnabled(SentryLevel.Error, exception, message); /// @@ -220,37 +227,41 @@ public static class DiagnosticLoggerExtensions /// internal static void LogError( this SentryOptions options, - string message, - Exception? exception = null) + string message) + => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, null, message); + + /// + /// Log a error message. + /// + internal static void LogError(this SentryOptions options, + Exception exception, + string message) => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, exception, message); /// /// Log a error message. /// - public static void LogError( - this IDiagnosticLogger logger, - string message, + public static void LogError(this IDiagnosticLogger logger, Exception exception, + string message, TArg arg) => logger.LogIfEnabled(SentryLevel.Error, exception, message, arg); /// /// Log a error message. /// - internal static void LogError( - this SentryOptions options, - string message, + internal static void LogError(this SentryOptions options, Exception exception, + string message, TArg arg) => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, exception, message, arg); /// /// Log a error message. /// - public static void LogError( - this IDiagnosticLogger logger, - string message, + public static void LogError(this IDiagnosticLogger logger, Exception exception, + string message, TArg arg, TArg2 arg2) => logger.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2); @@ -258,10 +269,9 @@ public static class DiagnosticLoggerExtensions /// /// Log a error message. /// - internal static void LogError( - this SentryOptions options, - string message, + internal static void LogError(this SentryOptions options, Exception exception, + string message, TArg arg, TArg2 arg2) => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2); @@ -269,10 +279,9 @@ public static class DiagnosticLoggerExtensions /// /// Log a error message. /// - public static void LogError( - this IDiagnosticLogger logger, - string message, + public static void LogError(this IDiagnosticLogger logger, Exception exception, + string message, TArg arg, TArg2 arg2, TArg3 arg3, @@ -282,10 +291,9 @@ public static class DiagnosticLoggerExtensions /// /// Log a error message. /// - internal static void LogError( - this SentryOptions options, - string message, + internal static void LogError(this SentryOptions options, Exception exception, + string message, TArg arg, TArg2 arg2, TArg3 arg3, @@ -321,8 +329,15 @@ public static class DiagnosticLoggerExtensions /// public static void LogFatal( this IDiagnosticLogger logger, - string message, - Exception? exception = null) + string message) + => logger.LogIfEnabled(SentryLevel.Fatal, null, message); + + /// + /// Log an exception with a warning message. + /// + public static void LogFatal(this IDiagnosticLogger logger, + Exception exception, + string message) => logger.LogIfEnabled(SentryLevel.Fatal, exception, message); /// @@ -330,8 +345,15 @@ public static class DiagnosticLoggerExtensions /// internal static void LogFatal( this SentryOptions options, - string message, - Exception? exception = null) + string message) + => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Fatal, null, message); + + /// + /// Log an exception with a warning message. + /// + internal static void LogFatal(this SentryOptions options, + Exception exception, + string message) => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Fatal, exception, message); internal static void LogIfEnabled( diff --git a/src/Sentry/GlobalSessionManager.cs b/src/Sentry/GlobalSessionManager.cs index 2a42f2b62d..3cbab88e42 100644 --- a/src/Sentry/GlobalSessionManager.cs +++ b/src/Sentry/GlobalSessionManager.cs @@ -85,7 +85,7 @@ internal class GlobalSessionManager : ISessionManager // and let the next installation id strategy kick in catch (Exception ex) { - _options.LogError("Failed to resolve persistent installation ID.", ex); + _options.LogError(ex, "Failed to resolve persistent installation ID."); return null; } } @@ -113,7 +113,7 @@ internal class GlobalSessionManager : ISessionManager } catch (Exception ex) { - _options.LogError("Failed to resolve hardware installation ID.", ex); + _options.LogError(ex, "Failed to resolve hardware installation ID."); return null; } } @@ -187,7 +187,7 @@ private void PersistSession(SessionUpdate update, DateTimeOffset? pauseTimestamp } catch (Exception ex) { - _options.LogError("Failed to persist session on the file system.", ex); + _options.LogError(ex, "Failed to persist session on the file system."); } } @@ -212,7 +212,7 @@ private void DeletePersistedSession() } catch (Exception ex) { - _options.LogError("Failed to read the contents of persisted session file '{0}'.", ex, filePath); + _options.LogError(ex, "Failed to read the contents of persisted session file '{0}'.", filePath); } } @@ -222,7 +222,7 @@ private void DeletePersistedSession() } catch (Exception ex) { - _options.LogError("Failed to delete persisted session from the file system: '{0}'", ex, filePath); + _options.LogError(ex, "Failed to delete persisted session from the file system: '{0}'", filePath); } } @@ -256,7 +256,7 @@ private void DeletePersistedSession() } catch (Exception e) { - _options.LogError("Invoking CrashedLastRun failed.", e); + _options.LogError(e, "Invoking CrashedLastRun failed."); } // Create a session update to end the recovered session @@ -285,7 +285,7 @@ private void DeletePersistedSession() } catch (Exception ex) { - _options.LogError("Failed to recover persisted session from the file system '{0}'.", ex, filePath); + _options.LogError(ex, "Failed to recover persisted session from the file system '{0}'.", filePath); return null; } diff --git a/src/Sentry/Integrations/NetFxInstallationsIntegration.cs b/src/Sentry/Integrations/NetFxInstallationsIntegration.cs index a37f9af36f..00060e8454 100644 --- a/src/Sentry/Integrations/NetFxInstallationsIntegration.cs +++ b/src/Sentry/Integrations/NetFxInstallationsIntegration.cs @@ -17,7 +17,7 @@ public void Register(IHub hub, SentryOptions options) } catch (Exception ex) { - options.LogError("Failed to register NetFxInstallations.", ex); + options.LogError(ex, "Failed to register NetFxInstallations."); } } } diff --git a/src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs b/src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs index 6690217054..6cae0bde4c 100644 --- a/src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs +++ b/src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs @@ -89,7 +89,7 @@ private void AttachEventHandler() } catch (Exception ex) { - _options.LogError("Could not attach WinUIUnhandledExceptionHandler.", ex); + _options.LogError(ex, "Could not attach WinUIUnhandledExceptionHandler."); } } @@ -105,7 +105,7 @@ private void WinUIUnhandledExceptionHandler(object sender, object e) } catch (Exception ex) { - _options.LogError("Could not get exception details in WinUIUnhandledExceptionHandler.", ex); + _options.LogError(ex, "Could not get exception details in WinUIUnhandledExceptionHandler."); return; } diff --git a/src/Sentry/Internal/BackgroundWorker.cs b/src/Sentry/Internal/BackgroundWorker.cs index a013841a0c..3e6ca09c16 100644 --- a/src/Sentry/Internal/BackgroundWorker.cs +++ b/src/Sentry/Internal/BackgroundWorker.cs @@ -167,11 +167,9 @@ private async Task DoWorkAsync() } catch (Exception exception) { - _options.LogError( + _options.LogError(exception, "Error while processing envelope (event ID: '{0}'). {1} items in queue.", - exception, - eventId, - _queue.Count); + eventId, _queue.Count); } finally { @@ -193,7 +191,7 @@ private async Task DoWorkAsync() } catch (Exception e) { - _options.LogFatal("Exception in the background worker.", e); + _options.LogFatal(e, "Exception in the background worker."); throw; } } @@ -314,8 +312,7 @@ private async Task SendFinalClientReportAsync(CancellationToken cancellationToke } catch (Exception exception) { - _options.LogError("Error while sending final client report (event ID: '{0}').", - exception, envelope.TryGetEventId(_options.DiagnosticLogger)); + _options.LogError(exception, "Error while sending final client report (event ID: '{0}').", envelope.TryGetEventId(_options.DiagnosticLogger)); } } } @@ -358,7 +355,7 @@ public void Dispose() } catch (Exception exception) { - _options.LogError("Stopping the background worker threw an exception.", exception); + _options.LogError(exception, "Stopping the background worker threw an exception."); } finally { diff --git a/src/Sentry/Internal/Http/CachingTransport.cs b/src/Sentry/Internal/Http/CachingTransport.cs index d5ac3261c9..93db1fbed4 100644 --- a/src/Sentry/Internal/Http/CachingTransport.cs +++ b/src/Sentry/Internal/Http/CachingTransport.cs @@ -147,7 +147,7 @@ private async Task CachedTransportBackgroundTaskAsync() } catch (Exception ex) { - _options.LogError("Exception in CachingTransport worker.", ex); + _options.LogError(ex, "Exception in CachingTransport worker."); try { @@ -209,9 +209,8 @@ private void MoveUnprocessedFilesBackToCache() } else { - _options.LogError( - "Failed to move unprocessed file back to cache (attempt {0}, done.): {1}", ex, - attempt, filePath); + _options.LogError(ex, + "Failed to move unprocessed file back to cache (attempt {0}, done.): {1}", attempt, filePath); } // note: we do *not* want to re-throw the exception @@ -321,7 +320,7 @@ await using (stream.ConfigureAwait(false)) catch (Exception ex) when (ex is HttpRequestException or WebException or SocketException or IOException) { - _options.LogError("Failed to send cached envelope: {0}, retrying after a delay.", ex, file); + _options.LogError(ex, "Failed to send cached envelope: {0}, retrying after a delay.", file); // Let the worker catch, log, wait a bit and retry. throw; } @@ -367,11 +366,11 @@ private void LogFailureWithDiscard(string file, Exception ex) if (envelopeContents == null) { - _options.LogError("Failed to send cached envelope: {0}, discarding cached envelope.", ex, file); + _options.LogError(ex, "Failed to send cached envelope: {0}, discarding cached envelope.", file); } else { - _options.LogError("Failed to send cached envelope: {0}, discarding cached envelope. Envelope contents: {1}", ex, file, envelopeContents); + _options.LogError(ex, "Failed to send cached envelope: {0}, discarding cached envelope. Envelope contents: {1}", file, envelopeContents); } } @@ -502,9 +501,7 @@ public async ValueTask DisposeAsync() catch (Exception ex) { // Don't throw inside dispose - _options.LogError( - "Error stopping worker during dispose.", - ex); + _options.LogError(ex, "Error stopping worker during dispose."); } _workerSignal.Dispose(); diff --git a/src/Sentry/Internal/Http/EnvelopeHttpContent.cs b/src/Sentry/Internal/Http/EnvelopeHttpContent.cs index 66c4565c99..5db14092a0 100644 --- a/src/Sentry/Internal/Http/EnvelopeHttpContent.cs +++ b/src/Sentry/Internal/Http/EnvelopeHttpContent.cs @@ -25,7 +25,7 @@ protected override async Task SerializeToStreamAsync(Stream stream, TransportCon } catch (Exception e) { - _logger?.LogError("Failed to serialize Envelope into the network stream", e); + _logger?.LogError(e, "Failed to serialize Envelope into the network stream"); throw; } } @@ -38,7 +38,7 @@ protected override void SerializeToStream(Stream stream, TransportContext? conte } catch (Exception e) { - _logger?.LogError("Failed to serialize Envelope into the network stream", e); + _logger?.LogError(e, "Failed to serialize Envelope into the network stream"); throw; } } diff --git a/src/Sentry/Internal/Hub.cs b/src/Sentry/Internal/Hub.cs index 8a361871c9..47e42adf0c 100644 --- a/src/Sentry/Internal/Hub.cs +++ b/src/Sentry/Internal/Hub.cs @@ -77,7 +77,7 @@ public void ConfigureScope(Action configureScope) } catch (Exception e) { - _options.LogError("Failure to ConfigureScope", e); + _options.LogError(e, "Failure to ConfigureScope"); } } @@ -89,7 +89,7 @@ public async Task ConfigureScopeAsync(Func configureScope) } catch (Exception e) { - _options.LogError("Failure to ConfigureScopeAsync", e); + _options.LogError(e, "Failure to ConfigureScopeAsync"); } } @@ -276,7 +276,7 @@ public void StartSession() } catch (Exception ex) { - _options.LogError("Failed to recover persisted session.", ex); + _options.LogError(ex, "Failed to recover persisted session."); } } @@ -291,7 +291,7 @@ public void StartSession() } catch (Exception ex) { - _options.LogError("Failed to start a session.", ex); + _options.LogError(ex, "Failed to start a session."); } } @@ -305,7 +305,7 @@ public void PauseSession() } catch (Exception ex) { - _options.LogError("Failed to pause a session.", ex); + _options.LogError(ex, "Failed to pause a session."); } } } @@ -323,7 +323,7 @@ public void ResumeSession() } catch (Exception ex) { - _options.LogError("Failed to resume a session.", ex); + _options.LogError(ex, "Failed to resume a session."); } } } @@ -340,7 +340,7 @@ private void EndSession(DateTimeOffset timestamp, SessionEndStatus status) } catch (Exception ex) { - _options.LogError("Failed to end a session.", ex); + _options.LogError(ex, "Failed to end a session."); } } @@ -398,7 +398,7 @@ public SentryId CaptureEvent(SentryEvent evt, Hint? hint, Action configur } catch (Exception e) { - _options.LogError("Failure to capture event: {0}", e, evt.EventId); + _options.LogError(e, "Failure to capture event: {0}", evt.EventId); return SentryId.Empty; } } @@ -448,7 +448,7 @@ SentryId IHubEx.CaptureEventInternal(SentryEvent evt, Hint? hint, Scope? scope) } catch (Exception e) { - _options.LogError("Failure to capture event: {0}", e, evt.EventId); + _options.LogError(e, "Failure to capture event: {0}", evt.EventId); return SentryId.Empty; } } @@ -466,7 +466,7 @@ public void CaptureUserFeedback(UserFeedback userFeedback) } catch (Exception e) { - _options.LogError("Failure to capture user feedback: {0}", e, userFeedback.EventId); + _options.LogError(e, "Failure to capture user feedback: {0}", userFeedback.EventId); } } @@ -518,7 +518,7 @@ public void CaptureTransaction(Transaction transaction, Hint? hint) } catch (Exception e) { - _options.LogError("Failure to capture transaction: {0}", e, transaction.SpanId); + _options.LogError(e, "Failure to capture transaction: {0}", transaction.SpanId); } } @@ -535,7 +535,7 @@ public void CaptureSession(SessionUpdate sessionUpdate) } catch (Exception e) { - _options.LogError("Failure to capture session update: {0}", e, sessionUpdate.Id); + _options.LogError(e, "Failure to capture session update: {0}", sessionUpdate.Id); } } @@ -548,7 +548,7 @@ public async Task FlushAsync(TimeSpan timeout) } catch (Exception e) { - _options.LogError("Failure to Flush events", e); + _options.LogError(e, "Failure to Flush events"); } } diff --git a/src/Sentry/Internal/ProcessInfo.cs b/src/Sentry/Internal/ProcessInfo.cs index 506d7aa66b..99b564020b 100644 --- a/src/Sentry/Internal/ProcessInfo.cs +++ b/src/Sentry/Internal/ProcessInfo.cs @@ -56,13 +56,11 @@ internal Task PreciseAppStartupTask // ArgumentOutOfRangeException: The added or subtracted value results in an un-representable DateTime. // https://github.com/getsentry/sentry-unity/issues/233 - options.LogError( + options.LogError(e, "Failed to find BootTime: Now {0}, GetTimestamp {1}, Frequency {2}, TicksPerSecond: {3}", - e, now, timestamp, - Stopwatch.Frequency, - TimeSpan.TicksPerSecond); + Stopwatch.Frequency, TimeSpan.TicksPerSecond); } // An opt-out to the more precise approach (mainly due to IL2CPP): @@ -85,7 +83,7 @@ internal Task PreciseAppStartupTask } catch (Exception e) { - options.LogError("Failure getting precise App startup time.", e); + options.LogError(e, "Failure getting precise App startup time."); //Ignore any exception and stay with the less-precise DateTime.UtcNow value. } }).ContinueWith(_ => diff --git a/src/Sentry/PlatformAbstractions/NetFxInstallationsEventProcessor.cs b/src/Sentry/PlatformAbstractions/NetFxInstallationsEventProcessor.cs index 2ff529c032..dd57ccd646 100644 --- a/src/Sentry/PlatformAbstractions/NetFxInstallationsEventProcessor.cs +++ b/src/Sentry/PlatformAbstractions/NetFxInstallationsEventProcessor.cs @@ -38,7 +38,7 @@ internal class NetFxInstallationsEventProcessor : ISentryEventProcessor } catch (Exception ex) { - _options.LogError("Failed to add NetFxInstallations into event.", ex); + _options.LogError(ex, "Failed to add NetFxInstallations into event."); // In case of any failure, this process function will be disabled to avoid throwing exceptions for future events. _netFxInstallationEnabled = false; diff --git a/src/Sentry/Platforms/Android/AndroidHelpers.cs b/src/Sentry/Platforms/Android/AndroidHelpers.cs index 62efba4854..0de68d6c62 100644 --- a/src/Sentry/Platforms/Android/AndroidHelpers.cs +++ b/src/Sentry/Platforms/Android/AndroidHelpers.cs @@ -45,7 +45,7 @@ public static IList GetSupportedAbis() } catch (Exception ex) { - logger?.LogError("Cannot create assembly reader.", ex); + logger?.LogError(ex, "Cannot create assembly reader."); return null; } } diff --git a/src/Sentry/Platforms/Android/AndroidScopeObserver.cs b/src/Sentry/Platforms/Android/AndroidScopeObserver.cs index 1958505d3c..2a8f3fad63 100644 --- a/src/Sentry/Platforms/Android/AndroidScopeObserver.cs +++ b/src/Sentry/Platforms/Android/AndroidScopeObserver.cs @@ -53,7 +53,7 @@ public void SetExtra(string key, object? value) } catch (Exception ex) { - _options.LogError("Extra with key '{0}' could not be serialized.", ex, key); + _options.LogError(ex, "Extra with key '{0}' could not be serialized.", key); } } finally diff --git a/src/Sentry/Platforms/iOS/Extensions/CocoaExtensions.cs b/src/Sentry/Platforms/iOS/Extensions/CocoaExtensions.cs index 69b86b19dd..f66dcc24a1 100644 --- a/src/Sentry/Platforms/iOS/Extensions/CocoaExtensions.cs +++ b/src/Sentry/Platforms/iOS/Extensions/CocoaExtensions.cs @@ -46,7 +46,7 @@ internal static class CocoaExtensions } catch (Exception ex) { - logger?.LogError("Error serializing {0} to JSON", ex, obj.GetType().Name); + logger?.LogError(ex, "Error serializing {0} to JSON", obj.GetType().Name); return null; } } diff --git a/src/Sentry/Platforms/iOS/IosScopeObserver.cs b/src/Sentry/Platforms/iOS/IosScopeObserver.cs index 5274aa1487..5a7baacac8 100644 --- a/src/Sentry/Platforms/iOS/IosScopeObserver.cs +++ b/src/Sentry/Platforms/iOS/IosScopeObserver.cs @@ -55,7 +55,7 @@ public void SetExtra(string key, object? value) } catch (Exception ex) { - _options.LogError("Extra with key '{0}' could not be serialized.", ex, key); + _options.LogError(ex, "Extra with key '{0}' could not be serialized.", key); } } finally diff --git a/src/Sentry/Protocol/Envelopes/Envelope.cs b/src/Sentry/Protocol/Envelopes/Envelope.cs index 76b3f02d0c..488f07ed93 100644 --- a/src/Sentry/Protocol/Envelopes/Envelope.cs +++ b/src/Sentry/Protocol/Envelopes/Envelope.cs @@ -269,7 +269,7 @@ internal void Serialize(Stream stream, IDiagnosticLogger? logger, ISystemClock c } catch (Exception exception) { - logger?.LogError("Failed to add attachment: {0}.", exception, attachment.FileName); + logger?.LogError(exception, "Failed to add attachment: {0}.", attachment.FileName); } } } diff --git a/src/Sentry/Scope.cs b/src/Sentry/Scope.cs index 1301ce75fd..10401a167e 100644 --- a/src/Sentry/Scope.cs +++ b/src/Sentry/Scope.cs @@ -527,7 +527,7 @@ internal void Evaluate() } catch (Exception ex) { - Options.DiagnosticLogger?.LogError("Failed invoking event handler.", ex); + Options.DiagnosticLogger?.LogError(ex, "Failed invoking event handler."); } finally { diff --git a/src/Sentry/SentryClient.cs b/src/Sentry/SentryClient.cs index d0d52dfe7e..4f22a65821 100644 --- a/src/Sentry/SentryClient.cs +++ b/src/Sentry/SentryClient.cs @@ -77,7 +77,7 @@ public SentryId CaptureEvent(SentryEvent? @event, Hint? hint, Scope? scope = nul } catch (Exception e) { - _options.LogError("An error occurred when capturing the event {0}.", e, @event.EventId); + _options.LogError(e, "An error occurred when capturing the event {0}.", @event.EventId); return SentryId.Empty; } } @@ -169,7 +169,7 @@ public void CaptureTransaction(Transaction transaction, Hint? hint) // Attempt to demystify exceptions before adding them as breadcrumbs. e.Demystify(); - _options.LogError("The BeforeSendTransaction callback threw an exception. It will be added as breadcrumb and continue.", e); + _options.LogError(e, "The BeforeSendTransaction callback threw an exception. It will be added as breadcrumb and continue."); var data = new Dictionary { @@ -372,7 +372,7 @@ private bool CaptureEnvelope(Envelope envelope) // Attempt to demystify exceptions before adding them as breadcrumbs. e.Demystify(); - _options.LogError("The BeforeSend callback threw an exception. It will be added as breadcrumb and continue.", e); + _options.LogError(e, "The BeforeSend callback threw an exception. It will be added as breadcrumb and continue."); var data = new Dictionary { {"message", e.Message} diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index 5c0d653b6b..7999d6c10f 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -868,7 +868,7 @@ public StackTraceMode StackTraceMode catch (Exception ex) { _stackTraceMode = StackTraceMode.Enhanced; - DiagnosticLogger?.LogError("Failed to get runtime, setting {0} to {1} ", ex, nameof(StackTraceMode), _stackTraceMode); + DiagnosticLogger?.LogError(ex, "Failed to get runtime, setting {0} to {1} ", nameof(StackTraceMode), _stackTraceMode); } return _stackTraceMode.Value;