Skip to content

Commit

Permalink
Extended logging for SentryLog:
Browse files Browse the repository at this point in the history
  - support for message and caller method name parameters
  • Loading branch information
PiotrKarczmarz committed Jan 28, 2025
1 parent 81bbefa commit 2d8ffb9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/Cody.Core/Logging/ISentryLog.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Runtime.CompilerServices;

namespace Cody.Core.Logging
{
public interface ISentryLog
{
void Error(Exception exception);
void Error(string message, Exception ex, [CallerMemberName] string callerName = "");

void Error(string message);
void Error(string message, [CallerMemberName] string callerName = "");
}
}
4 changes: 2 additions & 2 deletions src/Cody.Core/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Error(string message, [CallerMemberName] string callerName = "")
// TODO: _fileLogger.Error(customMessage);
DebugWrite(customMessage);
_outputWindowPane?.Error(message, callerName);
_sentryLog?.Error(customMessage);
_sentryLog?.Error(customMessage, callerName);
_testLogger?.WriteLog(message, "ERROR", callerName);
}

Expand All @@ -87,7 +87,7 @@ public void Error(string message, Exception ex, [CallerMemberName] string caller
// TODO: _fileLogger.Error(originalException, customMessage);
DebugWrite(customMessage);
_outputWindowPane?.Error(outputMessage, callerName);
_sentryLog?.Error(originalException);
_sentryLog?.Error(outputMessage, originalException, callerName);
_testLogger?.WriteLog(message, "ERROR", callerName);
}

Expand Down
16 changes: 12 additions & 4 deletions src/Cody.Core/Logging/SentryLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace Cody.Core.Logging
{
public class SentryLog : ISentryLog
{
public const string CodyAssemblyPrefix = "Cody.";

public void Error(Exception exception)
public void Error(string message, Exception ex, [CallerMemberName] string callerName = "")
{
SentrySdk.CaptureException(exception);
SentrySdk.CaptureException(ex, scope =>
{
scope.SetExtra(nameof(callerName), callerName);
scope.SetExtra(nameof(message), message);
});
}

public void Error(string message)
public void Error(string message, [CallerMemberName] string callerName = "")
{
SentrySdk.CaptureMessage(message);
SentrySdk.CaptureMessage(message, scope =>
{
scope.SetExtra(nameof(callerName), callerName);
});
}

public static void Initialize()
Expand Down

0 comments on commit 2d8ffb9

Please sign in to comment.