• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 8727898407

17 Apr 2024 07:50PM UTC coverage: 51.881% (-0.3%) from 52.205%
8727898407

push

github

pwelter34
improve query logging

1022 of 2496 branches covered (40.95%)

Branch coverage included in aggregate %.

49 of 67 new or added lines in 2 files covered. (73.13%)

43 existing lines in 1 file now uncovered.

2978 of 5214 relevant lines covered (57.12%)

747.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/FluentCommand/DataQueryFormatter.cs
1
using System.Data;
2

3
using FluentCommand.Internal;
4

5
namespace FluentCommand;
6

7
/// <summary>
8
/// A class to format an <see cref="IDbCommand"/> for logging
9
/// </summary>
10
public class DataQueryFormatter
11
    : IDataQueryFormatter
12
{
13
    /// <summary>
14
    /// Formats the command for logging.
15
    /// </summary>
16
    /// <param name="command">The command to log.</param>
17
    /// <param name="duration">The execution duration.</param>
18
    /// <param name="exception">The exception thrown when executing the command.</param>
19
    /// <returns>The command formatted as a string</returns>
20
    /// <exception cref="System.ArgumentNullException">command</exception>
21
    public string FormatCommand(IDbCommand command, TimeSpan duration, Exception exception)
22
    {
UNCOV
23
        if (command == null)
×
24
            throw new ArgumentNullException(nameof(command));
×
25

UNCOV
26
        var elapsed = duration.TotalMilliseconds;
×
UNCOV
27
        var commandType = command.CommandType;
×
UNCOV
28
        var commandTimeout = command.CommandTimeout;
×
UNCOV
29
        var resultText = exception == null ? "Executed" : "Error Executing";
×
30

UNCOV
31
        var buffer = StringBuilderCache.Acquire();
×
32

UNCOV
33
        buffer
×
UNCOV
34
            .Append(resultText)
×
UNCOV
35
            .Append(" DbCommand (")
×
UNCOV
36
            .Append(elapsed)
×
UNCOV
37
            .Append("ms) [CommandType='")
×
UNCOV
38
            .Append(commandType)
×
UNCOV
39
            .Append("', CommandTimeout='")
×
UNCOV
40
            .Append(commandTimeout)
×
UNCOV
41
            .Append("']")
×
UNCOV
42
            .AppendLine()
×
UNCOV
43
            .AppendLine(command.CommandText);
×
44

UNCOV
45
        foreach (IDataParameter parameter in command.Parameters)
×
46
        {
UNCOV
47
            int precision = 0;
×
UNCOV
48
            int scale = 0;
×
UNCOV
49
            int size = 0;
×
50

UNCOV
51
            if (parameter is IDbDataParameter dataParameter)
×
52
            {
UNCOV
53
                precision = dataParameter.Precision;
×
UNCOV
54
                scale = dataParameter.Scale;
×
UNCOV
55
                size = dataParameter.Size;
×
56
            }
57

UNCOV
58
            buffer
×
UNCOV
59
                .Append("-- ")
×
UNCOV
60
                .Append(parameter.ParameterName)
×
UNCOV
61
                .Append(": ")
×
UNCOV
62
                .Append(parameter.Direction)
×
UNCOV
63
                .Append(" ")
×
UNCOV
64
                .Append(parameter.DbType)
×
UNCOV
65
                .Append("(Size=")
×
UNCOV
66
                .Append(size)
×
UNCOV
67
                .Append("; Precision=")
×
UNCOV
68
                .Append(precision)
×
UNCOV
69
                .Append("; Scale=")
×
UNCOV
70
                .Append(scale)
×
UNCOV
71
                .Append(") [")
×
UNCOV
72
                .Append(parameter.Value)
×
UNCOV
73
                .Append("]")
×
UNCOV
74
                .AppendLine();
×
75
        }
76

UNCOV
77
        return StringBuilderCache.ToString(buffer);
×
78
    }
79

80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc