| | | 1 | | using Elsa.Workflows.Runtime.Entities; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Workflows.Runtime.Extensions; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Provides extension methods for sanitizing log messages. |
| | | 7 | | /// </summary> |
| | | 8 | | public static class LogExtensions |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Sanitizes a log message by replacing null characters with the string "\0". |
| | | 12 | | /// This is especially useful when storing messages in PostgreSQL, which does not allow null characters in strings. |
| | | 13 | | /// </summary> |
| | | 14 | | public static WorkflowExecutionLogRecord SanitizeLogMessage(this WorkflowExecutionLogRecord record) |
| | | 15 | | { |
| | 4769 | 16 | | record.Message = record.Message.SanitizeLogMessage(); |
| | 4769 | 17 | | return record; |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Sanitizes a log message by replacing null characters with the string "\0". |
| | | 22 | | /// This is especially useful when storing messages in PostgreSQL, which does not allow null characters in strings. |
| | | 23 | | /// </summary> |
| | | 24 | | public static ActivityExecutionRecord SanitizeLogMessage(this ActivityExecutionRecord record) |
| | | 25 | | { |
| | 3832 | 26 | | if (record.Exception != null) |
| | 8 | 27 | | record.Exception = record.Exception with |
| | 8 | 28 | | { |
| | 8 | 29 | | Message = record.Exception.Message.SanitizeLogMessage()! |
| | 8 | 30 | | }; |
| | | 31 | | |
| | 3832 | 32 | | return record; |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Sanitizes a log message by replacing null characters with the string "\0". |
| | | 37 | | /// This is especially useful when storing messages in PostgreSQL, which does not allow null characters in strings. |
| | | 38 | | /// </summary> |
| | | 39 | | public static string? SanitizeLogMessage(this string? message) |
| | | 40 | | { |
| | 4777 | 41 | | return message?.Replace("\0", "\\0"); |
| | | 42 | | } |
| | | 43 | | } |