< Summary

Class:Azure.Security.KeyVault.Keys.KeysEventSource
Assembly:Azure.Security.KeyVault.Keys
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\KeysEventSource.cs
Covered lines:29
Uncovered lines:2
Coverable lines:31
Total lines:96
Line coverage:93.5% (29 of 31)
Covered branches:11
Total branches:14
Branch coverage:78.5% (11 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
get_Singleton()-100%100%
AlgorithmNotSupported(...)-100%100%
AlgorithmNotSupported(...)-100%100%
KeyTypeNotSupported(...)-100%66.67%
KeyTypeNotSupported(...)-100%100%
PrivateKeyRequired(...)-100%100%
CryptographicException(...)-100%100%
CryptographicException(...)-100%100%
FormatException(...)-85.71%75%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\KeysEventSource.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Diagnostics.Tracing;
 6using System.Globalization;
 7using System.Text;
 8using Azure.Core.Diagnostics;
 9
 10namespace Azure.Security.KeyVault.Keys
 11{
 12    [EventSource(Name = EventSourceName)]
 13    internal sealed class KeysEventSource : EventSource
 14    {
 15        internal const int AlgorithmNotSupportedEvent = 1;
 16        internal const int KeyTypeNotSupportedEvent = 2;
 17        internal const int PrivateKeyRequiredEvent = 3;
 18        internal const int CryptographicExceptionEvent = 4;
 19
 20        private const string EventSourceName = "Azure-Security-KeyVault-Keys";
 21
 422        private KeysEventSource() : base(EventSourceName, EventSourceSettings.Default, AzureEventSourceListener.TraitNam
 23
 26024        public static KeysEventSource Singleton { get; } = new KeysEventSource();
 25
 26        [NonEvent]
 27        public void AlgorithmNotSupported<T>(string operation, T algorithm) where T : notnull
 28        {
 4429            if (IsEnabled())
 30            {
 4031                AlgorithmNotSupported(operation, algorithm.ToString());
 32            }
 4433        }
 34
 35        [Event(AlgorithmNotSupportedEvent, Level = EventLevel.Verbose, Message = "The algorithm {1} is not supported on 
 4036        public void AlgorithmNotSupported(string operation, string algorithm) => WriteEvent(AlgorithmNotSupportedEvent, 
 37
 38        [NonEvent]
 39        public void KeyTypeNotSupported(string operation, KeyVaultKey key)
 40        {
 2441            if (IsEnabled())
 42            {
 2443                string keyType = key?.KeyType.ToString() ?? "(null)";
 2444                KeyTypeNotSupported(operation, keyType);
 45            }
 2446        }
 47
 48        [Event(KeyTypeNotSupportedEvent, Level = EventLevel.Verbose, Message = "The key type {1} is not supported on thi
 2449        public void KeyTypeNotSupported(string operation, string keyType) => WriteEvent(KeyTypeNotSupportedEvent, operat
 50
 51        [Event(PrivateKeyRequiredEvent, Level = EventLevel.Verbose, Message = "A private key is required for a {0} opera
 5852        public void PrivateKeyRequired(string operation) => WriteEvent(PrivateKeyRequiredEvent, operation);
 53
 54        [NonEvent]
 55        public void CryptographicException(string operation, Exception ex)
 56        {
 2457            if (IsEnabled())
 58            {
 2459                string message = FormatException(ex);
 2460                CryptographicException(operation, message);
 61            }
 2462        }
 63
 64        [Event(CryptographicExceptionEvent, Level = EventLevel.Informational, Message = "A cryptographic exception occur
 2465        public void CryptographicException(string operation, string message) => WriteEvent(CryptographicExceptionEvent, 
 66
 67        private static string FormatException(Exception ex)
 68        {
 2469            StringBuilder sb = new StringBuilder();
 2470            bool nest = false;
 71
 72            do
 73            {
 2474                if (nest)
 75                {
 76                    // Format how Exception.ToString() would.
 077                    sb.AppendLine()
 078                      .Append(" ---> ");
 79                }
 80
 81                // Do not include StackTrace, but do include HResult (often useful for CryptographicExceptions or IOExce
 2482                sb.Append(ex.GetType().FullName)
 2483                  .Append(" (0x")
 2484                  .Append(ex.HResult.ToString("x", CultureInfo.InvariantCulture))
 2485                  .Append("): ")
 2486                  .Append(ex.Message);
 87
 2488                ex = ex.InnerException;
 2489                nest = true;
 90            }
 2491            while (ex != null);
 92
 2493            return sb.ToString();
 94        }
 95    }
 96}