Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended logging for SentryLog #204

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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