Skip to content

Commit

Permalink
fix: Added missing logging extension (#3630)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes authored Sep 26, 2024
1 parent e94bb05 commit 12c7d7c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

### Features

- Added a flag to options `DisableFileWrite` to allow users to opt-out of all file writing operations. Note that toggling this will affect features such as offline caching and auto-session tracking and release health as these rely on some file persistency ([#3614](https://github.com/getsentry/sentry-dotnet/pull/3614))
- Added a flag to options `DisableFileWrite` to allow users to opt-out of all file writing operations. Note that toggling this will affect features such as offline caching and auto-session tracking and release health as these rely on some file persistency ([#3614](https://github.com/getsentry/sentry-dotnet/pull/3614))

### Dependencies

Expand Down
105 changes: 73 additions & 32 deletions src/Sentry/Extensibility/DiagnosticLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ public static void LogError<TArg>(
/// <summary>
/// Log an exception with an error message.
/// </summary>
public static void LogError(this IDiagnosticLogger logger,
public static void LogError(
this IDiagnosticLogger logger,
Exception exception,
string message)
=> logger.LogIfEnabled(SentryLevel.Error, exception, message);
Expand All @@ -280,15 +281,17 @@ internal static void LogError(
/// <summary>
/// Log a error message.
/// </summary>
internal static void LogError(this SentryOptions options,
internal static void LogError(
this SentryOptions options,
Exception exception,
string message)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, exception, message);

/// <summary>
/// Log a error message.
/// </summary>
public static void LogError<TArg>(this IDiagnosticLogger logger,
public static void LogError<TArg>(
this IDiagnosticLogger logger,
Exception exception,
string message,
TArg arg)
Expand All @@ -297,7 +300,8 @@ public static void LogError<TArg>(this IDiagnosticLogger logger,
/// <summary>
/// Log a error message.
/// </summary>
internal static void LogError<TArg>(this SentryOptions options,
internal static void LogError<TArg>(
this SentryOptions options,
Exception exception,
string message,
TArg arg)
Expand All @@ -306,7 +310,17 @@ internal static void LogError<TArg>(this SentryOptions options,
/// <summary>
/// Log a error message.
/// </summary>
public static void LogError<TArg, TArg2>(this IDiagnosticLogger logger,
internal static void LogError<TArg>(
this SentryOptions options,
string message,
TArg arg)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, null, message, arg);

/// <summary>
/// Log a error message.
/// </summary>
public static void LogError<TArg, TArg2>(
this IDiagnosticLogger logger,
Exception exception,
string message,
TArg arg,
Expand All @@ -316,7 +330,8 @@ public static void LogError<TArg, TArg2>(this IDiagnosticLogger logger,
/// <summary>
/// Log a error message.
/// </summary>
internal static void LogError<TArg, TArg2>(this SentryOptions options,
internal static void LogError<TArg, TArg2>(
this SentryOptions options,
Exception exception,
string message,
TArg arg,
Expand All @@ -326,73 +341,99 @@ internal static void LogError<TArg, TArg2>(this SentryOptions options,
/// <summary>
/// Log a error message.
/// </summary>
public static void LogError<TArg, TArg2, TArg3, TArg4>(this IDiagnosticLogger logger,
internal static void LogError<TArg, TArg2>(
this SentryOptions options,
string message,
TArg arg,
TArg2 arg2)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, null, message, arg, arg2);


/// <summary>
/// Log an error message.
/// </summary>
public static void LogError<TArg, TArg2, TArg3>(
this IDiagnosticLogger logger,
Exception exception,
string message,
TArg arg,
TArg2 arg2,
TArg3 arg3,
TArg4 arg4)
=> logger.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2, arg3, arg4);
TArg3 arg3)
=> logger.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2, arg3);

/// <summary>
/// Log a error message.
/// Log an error message.
/// </summary>
internal static void LogError<TArg, TArg2, TArg3, TArg4>(this SentryOptions options,
internal static void LogError<TArg, TArg2, TArg3>(
this SentryOptions options,
Exception exception,
string message,
TArg arg,
TArg2 arg2,
TArg3 arg3,
TArg4 arg4)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2, arg3, arg4);
TArg3 arg3)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2, arg3);

/// <summary>
/// Log an error message.
/// </summary>
internal static void LogError<TArg, TArg2, TArg3>(
this SentryOptions options,
string message,
TArg arg,
TArg2 arg2,
TArg3 arg3)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, null, message, arg, arg2, arg3);

/// <summary>
/// Log a error message.
/// </summary>
internal static void LogError<TArg, TArg2, TArg3, TArg4, TArg5>(this SentryOptions options,
public static void LogError<TArg, TArg2, TArg3, TArg4>(
this IDiagnosticLogger logger,
Exception exception,
string message,
TArg arg,
TArg2 arg2,
TArg3 arg3,
TArg4 arg4,
TArg5 arg5)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, null, message, arg, arg2, arg3, arg4, arg5);
TArg4 arg4)
=> logger.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2, arg3, arg4);

/// <summary>
/// Log a error message.
/// </summary>
internal static void LogError<TArg, TArg2, TArg3, TArg4>(this SentryOptions options,
internal static void LogError<TArg, TArg2, TArg3, TArg4>(
this SentryOptions options,
Exception exception,
string message,
TArg arg,
TArg2 arg2,
TArg3 arg3,
TArg4 arg4)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, null, message, arg, arg2, arg3, arg4);
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2, arg3, arg4);

/// <summary>
/// Log an error message.
/// Log a error message.
/// </summary>
public static void LogError<TArg, TArg2, TArg3>(
this IDiagnosticLogger logger,
Exception exception,
internal static void LogError<TArg, TArg2, TArg3, TArg4>(
this SentryOptions options,
string message,
TArg arg,
TArg2 arg2,
TArg3 arg3)
=> logger.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2, arg3);
TArg3 arg3,
TArg4 arg4)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, null, message, arg, arg2, arg3, arg4);

/// <summary>
/// Log an error message.
/// Log a error message.
/// </summary>
internal static void LogError<TArg, TArg2, TArg3>(
internal static void LogError<TArg, TArg2, TArg3, TArg4, TArg5>(
this SentryOptions options,
Exception exception,
string message,
TArg arg,
TArg2 arg2,
TArg3 arg3)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2, arg3);
TArg3 arg3,
TArg4 arg4,
TArg5 arg5)
=> options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, null, message, arg, arg2, arg3, arg4, arg5);

/// <summary>
/// Log a warning message.
Expand Down
8 changes: 4 additions & 4 deletions src/Sentry/Http/HttpTransportBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,14 @@ private void HandleFailure(HttpResponseMessage response, Envelope envelope)
var createDirectoryResult = _options.FileSystem.CreateDirectory(Path.GetDirectoryName(destination)!);
if (createDirectoryResult is not FileOperationResult.Success)
{
_options.DiagnosticLogger.LogError("Failed to create directory to store the envelope: {0}", createDirectoryResult);
_options.LogError("Failed to create directory to store the envelope: {0}", createDirectoryResult);
return;
}

var result = _options.FileSystem.CreateFileForWriting(destination, out var envelopeFile);
if (result is not FileOperationResult.Success)
{
_options.DiagnosticLogger.LogError("Failed to create envelope file: {0}", result);
_options.LogError("Failed to create envelope file: {0}", result);
return;
}

Expand Down Expand Up @@ -455,14 +455,14 @@ private async Task HandleFailureAsync(HttpResponseMessage response, Envelope env
var createDirectoryResult = _options.FileSystem.CreateDirectory(Path.GetDirectoryName(destination)!);
if (createDirectoryResult is not FileOperationResult.Success)
{
_options.DiagnosticLogger.LogError("Failed to create directory to store the envelope: {0}", createDirectoryResult);
_options.LogError("Failed to create directory to store the envelope: {0}", createDirectoryResult);
return;
}

var result = _options.FileSystem.CreateFileForWriting(destination, out var envelopeFile);
if (result is not FileOperationResult.Success)
{
_options.DiagnosticLogger.LogError("Failed to create envelope file: {0}", result);
_options.LogError("Failed to create envelope file: {0}", result);
return;
}

Expand Down

0 comments on commit 12c7d7c

Please sign in to comment.