* Fix callback clearing in workflow execution The method ClearCompletionCallbacks in the ActivityExecutionContext was modifying the collection during enumeration, which can lead to issues. Converting to a List before removal ensures safe modification without side effects. * Add log message sanitization for PostgreSQL The new LogStringExtensions class provides methods to sanitize log messages, ensuring that null characters are replaced with "\0". These changes prevent issues with PostgreSQL's inability to store null characters in strings, improving log data compatibility with the database. * Rename and update log extension class Refactor LogStringExtensions to LogExtensions and update summary comment for clarity. This change emphasizes the broader application of the extension methods beyond string manipulation, focusing on sanitizing log messages.
43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using Elsa.Workflows.Runtime.Entities;
|
|
|
|
namespace Elsa.Workflows.Runtime.Extensions;
|
|
|
|
/// <summary>
|
|
/// Provides extension methods for sanitizing log messages.
|
|
/// </summary>
|
|
public static class LogExtensions
|
|
{
|
|
/// <summary>
|
|
/// Sanitizes a log message by replacing null characters with the string "\0".
|
|
/// This is especially useful when storing messages in PostgreSQL, which does not allow null characters in strings.
|
|
/// </summary>
|
|
public static WorkflowExecutionLogRecord SanitizeLogMessage(this WorkflowExecutionLogRecord record)
|
|
{
|
|
record.Message = record.Message.SanitizeLogMessage();
|
|
return record;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sanitizes a log message by replacing null characters with the string "\0".
|
|
/// This is especially useful when storing messages in PostgreSQL, which does not allow null characters in strings.
|
|
/// </summary>
|
|
public static ActivityExecutionRecord SanitizeLogMessage(this ActivityExecutionRecord record)
|
|
{
|
|
if (record.Exception != null)
|
|
record.Exception = record.Exception with
|
|
{
|
|
Message = record.Exception.Message.SanitizeLogMessage()!
|
|
};
|
|
|
|
return record;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sanitizes a log message by replacing null characters with the string "\0".
|
|
/// This is especially useful when storing messages in PostgreSQL, which does not allow null characters in strings.
|
|
/// </summary>
|
|
public static string? SanitizeLogMessage(this string? message)
|
|
{
|
|
return message?.Replace("\0", "\\0");
|
|
}
|
|
} |