< Summary

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

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
Format(...)-100%100%
ProcessPayloadArray(...)-100%100%
FormatValue(...)-100%100%

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        {
 815            var payloadArray = eventData.Payload.ToArray();
 16
 817            ProcessPayloadArray(payloadArray);
 18
 819            if (eventData.Message != null)
 20            {
 621                return string.Format(CultureInfo.InvariantCulture, eventData.Message, payloadArray);
 22            }
 23
 224            var stringBuilder = new StringBuilder();
 225            stringBuilder.Append(eventData.EventName);
 26
 1227            for (int i = 0; i < eventData.PayloadNames.Count; i++)
 28            {
 429                stringBuilder.AppendLine();
 430                stringBuilder.Append(eventData.PayloadNames[i]).Append(" = ").Append(payloadArray[i]);
 31            }
 32
 233            return stringBuilder.ToString();
 34        }
 35
 36        private static void ProcessPayloadArray(object[] payloadArray)
 37        {
 5238            for (int i = 0; i < payloadArray.Length; i++)
 39            {
 1840                payloadArray[i] = FormatValue(payloadArray[i]);
 41            }
 842        }
 43
 44        private static object FormatValue(object o)
 45        {
 1846            if (o is byte[] bytes)
 47            {
 248                var stringBuilder = new StringBuilder();
 1649                foreach (byte b in bytes)
 50                {
 651                    stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}", b);
 52                }
 53
 254                return stringBuilder.ToString();
 55            }
 56
 1657            return o;
 58        }
 59    }
 60}