< Summary

Information
Class: Elsa.Workflows.Runtime.Extensions.LogExtensions
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/LogExtensions.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 43
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SanitizeLogMessage(...)100%11100%
SanitizeLogMessage(...)100%22100%
SanitizeLogMessage(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/LogExtensions.cs

#LineLine coverage
 1using Elsa.Workflows.Runtime.Entities;
 2
 3namespace Elsa.Workflows.Runtime.Extensions;
 4
 5/// <summary>
 6/// Provides extension methods for sanitizing log messages.
 7/// </summary>
 8public 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    {
 476916        record.Message = record.Message.SanitizeLogMessage();
 476917        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    {
 383226        if (record.Exception != null)
 827            record.Exception = record.Exception with
 828            {
 829                Message = record.Exception.Message.SanitizeLogMessage()!
 830            };
 31
 383232        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    {
 477741        return message?.Replace("\0", "\\0");
 42    }
 43}