using Elsa.Workflows.Runtime.Entities; namespace Elsa.Workflows.Runtime.Extensions; /// /// Provides extension methods for sanitizing log messages. /// public static class LogExtensions { /// /// 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. /// public static WorkflowExecutionLogRecord SanitizeLogMessage(this WorkflowExecutionLogRecord record) { record.Message = record.Message.SanitizeLogMessage(); return record; } /// /// 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. /// public static ActivityExecutionRecord SanitizeLogMessage(this ActivityExecutionRecord record) { if (record.Exception != null) record.Exception = record.Exception with { Message = record.Exception.Message.SanitizeLogMessage()! }; return record; } /// /// 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. /// public static string? SanitizeLogMessage(this string? message) { return message?.Replace("\0", "\\0"); } }