コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StorageClientProvider{TClient, TClientOptions}"/> class that uses the registered Azure services.
        /// </summary>
        /// <param name="componentFactory">The Azure factory responsible for creating clients. <see cref="AzureComponentFactory"/>.</param>
        /// <param name="logForwarder">Log forwarder that forwards events to ILogger. <see cref="AzureEventSourceLogForwarder"/>.</param>
        public StorageClientProvider(AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder)
        {
            _componentFactory = componentFactory;
            _logForwarder     = logForwarder;

            _logForwarder.Start();
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StorageClientProvider{TClient, TClientOptions}"/> class that uses the registered Azure services.
        /// </summary>
        /// <param name="configuration">The configuration to use when creating Client-specific objects. <see cref="IConfiguration"/></param>
        /// <param name="componentFactory">The Azure factory responsible for creating clients. <see cref="AzureComponentFactory"/></param>
        /// <param name="logForwarder">Log forwarder that forwards events to ILogger. <see cref="AzureEventSourceLogForwarder"/></param>
        /// <param name="logger">Logger used when there is an error creating a client</param>
        public StorageClientProvider(IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger <TClient> logger)
        {
            _configuration    = configuration;
            _componentFactory = componentFactory;
            _logForwarder     = logForwarder;
            _logger           = logger;

            _logForwarder?.Start();
        }
コード例 #3
0
 public ServiceBusClientFactory(
     IConfiguration configuration,
     AzureComponentFactory componentFactory,
     MessagingProvider messagingProvider,
     AzureEventSourceLogForwarder logForwarder)
 {
     _configuration     = configuration;
     _componentFactory  = componentFactory;
     _messagingProvider = messagingProvider;
     logForwarder.Start();
 }
コード例 #4
0
 public ServiceBusClientFactory(
     IConfiguration configuration,
     AzureComponentFactory componentFactory,
     MessagingProvider messagingProvider,
     AzureEventSourceLogForwarder logForwarder,
     IOptions <ServiceBusOptions> options)
 {
     _configuration     = configuration;
     _componentFactory  = componentFactory;
     _messagingProvider = messagingProvider;
     _options           = options?.Value ?? throw new ArgumentNullException(nameof(options));
     logForwarder.Start();
 }
コード例 #5
0
        public void MapsLevelsCorrectly(EventLevel eventLevel, LogLevel logLevel)
        {
            var loggerFactory = new MockLoggerFactory();

            using (var forwarder = new AzureEventSourceLogForwarder(loggerFactory))
            {
                forwarder.Start();
                typeof(TestSource).GetMethod(eventLevel.ToString(), BindingFlags.Instance | BindingFlags.Public).Invoke(TestSource.Log, Array.Empty <object>());
            }

            var logs = loggerFactory.Loggers["Test.source"].Logs;

            Assert.AreEqual(1, logs.Count);
            Assert.AreEqual(logLevel, logs[0].Level);
        }
コード例 #6
0
        public virtual TClient Get(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = ConnectionStringNames.Storage; // default
            }

            // $$$ Where does validation happen?
            IConfigurationSection connectionSection = _configuration.GetWebJobsConnectionStringSection(name);

            if (!connectionSection.Exists())
            {
                // Not found
                throw new InvalidOperationException($"Storage account connection string '{IConfigurationExtensions.GetPrefixedConnectionStringName(name)}' does not exist. Make sure that it is a defined App Setting.");
            }

            _logForwarder.Start();
            var credential = _componentFactory.CreateTokenCredential(connectionSection);
            var options    = CreateClientOptions(connectionSection);

            return(CreateClient(connectionSection, credential, options));
        }
コード例 #7
0
        public virtual TClient Get(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = ConnectionStringNames.Storage; // default
            }

            // $$$ Where does validation happen?
            IConfigurationSection connectionSection = _configuration.GetWebJobsConnectionStringSection(name);

            if (!connectionSection.Exists())
            {
                // Not found
                throw new InvalidOperationException($"Storage account connection string '{IConfigurationExtensions.GetPrefixedConnectionStringName(name)}' does not exist. Make sure that it is a defined App Setting.");
            }

            _logForwarder.Start();

            if (!string.IsNullOrWhiteSpace(connectionSection.Value))
            {
                return(CreateClientFromConnectionString(connectionSection.Value, CreateClientOptions(null)));
            }

            var endpoint = connectionSection["endpoint"];

            if (string.IsNullOrWhiteSpace(endpoint))
            {
                // Not found
                throw new InvalidOperationException($"Connection should have an 'endpoint' property or be a string representing a connection string.");
            }

            var credential  = _componentFactory.CreateTokenCredential(connectionSection);
            var endpointUri = new Uri(endpoint);

            return(CreateClientFromTokenCredential(endpointUri, credential, CreateClientOptions(connectionSection)));
        }
コード例 #8
0
 public void WorksWithNullLoggerFactory()
 {
     using var forwarder = new AzureEventSourceLogForwarder(null);
     forwarder.Start();
     TestSource.Log.Informational();
 }