< Summary

Class:Azure.Core.Shared.EventSourceEventFormatting
Assembly:Microsoft.Extensions.Azure
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\EventSourceEventFormatting.cs
Covered lines:5
Uncovered lines:14
Coverable lines:19
Total lines:60
Line coverage:26.3% (5 of 19)
Covered branches:2
Total branches:10
Branch coverage:20% (2 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
Format(...)-40%25%
ProcessPayloadArray(...)-33.33%50%
FormatValue(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\EventSourceEventFormatting.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Diagnostics.Tracing;
 5using System.Globalization;
 6using System.Linq;
 7using System.Text;
 8
 9namespace Azure.Core.Shared
 10{
 11    internal static class EventSourceEventFormatting
 12    {
 13        public static string Format(EventWrittenEventArgs eventData)
 14        {
 1215            var payloadArray = eventData.Payload.ToArray();
 16
 1217            ProcessPayloadArray(payloadArray);
 18
 1219            if (eventData.Message != null)
 20            {
 1221                return string.Format(CultureInfo.InvariantCulture, eventData.Message, payloadArray);
 22            }
 23
 024            var stringBuilder = new StringBuilder();
 025            stringBuilder.Append(eventData.EventName);
 26
 027            for (int i = 0; i < eventData.PayloadNames.Count; i++)
 28            {
 029                stringBuilder.AppendLine();
 030                stringBuilder.Append(eventData.PayloadNames[i]).Append(" = ").Append(payloadArray[i]);
 31            }
 32
 033            return stringBuilder.ToString();
 34        }
 35
 36        private static void ProcessPayloadArray(object[] payloadArray)
 37        {
 038            for (int i = 0; i < payloadArray.Length; i++)
 39            {
 040                payloadArray[i] = FormatValue(payloadArray[i]);
 41            }
 1242        }
 43
 44        private static object FormatValue(object o)
 45        {
 046            if (o is byte[] bytes)
 47            {
 048                var stringBuilder = new StringBuilder();
 049                foreach (byte b in bytes)
 50                {
 051                    stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}", b);
 52                }
 53
 054                return stringBuilder.ToString();
 55            }
 56
 057            return o;
 58        }
 59    }
 60}