Skip to content

Commit e2a1c1b

Browse files
committed
Don't include file information in FailedState.ExceptionDetails
This information is usually less important, but may take a lot of additional space in the job storage.
1 parent fe6f303 commit e2a1c1b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: src/Hangfire.Core/Common/ShallowExceptionHelper.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void PreserveOriginalStackTrace(this Exception exception)
2828
{
2929
if (exception != null && !exception.Data.Contains(DataKey))
3030
{
31-
exception.Data.Add(DataKey, exception.StackTrace);
31+
exception.Data.Add(DataKey, GetStackTraceNoFileInfo(exception));
3232
}
3333
}
3434

@@ -58,7 +58,7 @@ private static string ToStringHelper(Exception exception, bool isInner)
5858
}
5959
else sb.Append('\n');
6060

61-
var stackTrace = exception.Data.Contains(DataKey) ? (string)exception.Data[DataKey] : exception.StackTrace;
61+
var stackTrace = exception.Data.Contains(DataKey) ? (string)exception.Data[DataKey] : GetStackTraceNoFileInfo(exception);
6262
if (!String.IsNullOrWhiteSpace(stackTrace))
6363
{
6464
sb.Append(stackTrace);
@@ -91,5 +91,14 @@ private static string GetFirstLines(string text, int? numLines)
9191
return builder.ToString();
9292
}
9393
}
94+
95+
private static string GetStackTraceNoFileInfo(Exception ex)
96+
{
97+
#if NETSTANDARD1_3
98+
return ex.StackTrace;
99+
#else
100+
return new System.Diagnostics.StackTrace(ex, fNeedFileInfo: false).ToString();
101+
#endif
102+
}
94103
}
95104
}

0 commit comments

Comments
 (0)