Log with caller (#9976)

This commit is contained in:
DHR60
2026-08-17 06:33:33 +00:00
committed by GitHub
parent 5e6660aeee
commit 7be264c65c
+9 -3
View File
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace ServiceLib.Common; namespace ServiceLib.Common;
@@ -138,7 +139,10 @@ public static class Extension
public static async Task<TOutput> HandleSafe<TInput, TOutput>( public static async Task<TOutput> HandleSafe<TInput, TOutput>(
this Interaction<TInput, TOutput> interaction, this Interaction<TInput, TOutput> interaction,
TInput input, TInput input,
TOutput defaultValue = default!) TOutput defaultValue = default!,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0)
{ {
try try
{ {
@@ -146,12 +150,14 @@ public static class Extension
} }
catch (UnhandledInteractionException<TInput, TOutput> ex) catch (UnhandledInteractionException<TInput, TOutput> ex)
{ {
Logging.SaveLog($"Unhandled interaction exception for input: {input}", ex); var title = $"Unhandled interaction exception in {memberName} at {filePath}:{lineNumber}";
Logging.SaveLog(title, ex);
return defaultValue; return defaultValue;
} }
catch (Exception ex) catch (Exception ex)
{ {
Logging.SaveLog($"Exception occurred while handling interaction for input: {input}", ex); var title = $"Exception occurred while handling interaction in {memberName} at {filePath}:{lineNumber}, input: {input}";
Logging.SaveLog(title, ex);
return defaultValue; return defaultValue;
} }
} }