Esempio n. 1
0
        /// <summary>
        /// Initializes a subscription tracking service based on the supplied
        /// <paramref name="configuration"/>
        /// </summary>
        /// <param name="configuration">The subscription tracking configuration</param>
        /// <returns>Returns a task whose result is the initialized subscription tracking service</returns>
        public async Task <IDiagnosticEventSink> InitDiagnosticEventSink(IConfiguration configuration)
        {
            var name         = configuration?["name"];
            var providerName = configuration?["provider"];

            if (string.IsNullOrWhiteSpace(providerName))
            {
                var message = "Provider not specified for diagnostic event sink '" + name + "'";
                await _diagnosticService.EmitAsync(
                    new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationError)
                {
                    Detail = message
                }.Build());

                throw new ConfigurationErrorsException(message);
            }

            var provider = GetProvider(providerName);

            if (provider == null)
            {
                var message = "Unknown provider '" + providerName + "' specified for diagnostic event sink '" + name + "'";
                await _diagnosticService.EmitAsync(
                    new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationError)
                {
                    Detail = message
                }.Build());

                throw new ConfigurationErrorsException(message);
            }

            await _diagnosticService.EmitAsync(
                new DiagnosticEventBuilder(this, DiagnosticEventType.ComponentInitialization)
            {
                Detail = "Initializing diagnostic event sink '" + name + "'"
            }.Build());

            var minLevel = configuration.GetValue("minLevel", DiagnosticEventLevel.Debug);
            var maxLevel = configuration.GetValue("minLevel", DiagnosticEventLevel.Error);
            var sink     = await provider.CreateDiagnosticEventSink(configuration);

            var filterSpec = new DiagnosticEventLevelSpecification(minLevel, maxLevel);
            var filterSink = new FilteringSink(sink, filterSpec);

            await _diagnosticService.EmitAsync(
                new DiagnosticEventBuilder(this, DiagnosticEventType.ComponentInitialization)
            {
                Detail = "Diagnostic event sink '" + name + "' initialized"
            }.Build());

            return(filterSink);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a subscription tracking service based on the supplied
        /// <paramref name="configuration"/>
        /// </summary>
        /// <param name="configuration">The subscription tracking configuration</param>
        /// <returns>Returns a task whose result is the initialized subscription tracking service</returns>
        public async Task <IDiagnosticEventSink> InitDiagnosticEventSink(DiagnosticEventSinkElement configuration)
        {
            var myConfig = configuration ?? new DiagnosticEventSinkElement();

            if (string.IsNullOrWhiteSpace(myConfig.Provider))
            {
                var message = "Provider not specified for diagnostic event sink '" + myConfig.Name + "'";
                await _diagnosticService.EmitAsync(
                    new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationError)
                {
                    Detail = message
                }.Build());

                throw new ConfigurationErrorsException(message);
            }

            var provider = GetProvider(myConfig.Provider);

            if (provider == null)
            {
                var message = "Unknown provider '" + myConfig.Provider + "' specified for diagnostic event sink '" + myConfig.Name + "'";
                await _diagnosticService.EmitAsync(
                    new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationError)
                {
                    Detail = message
                }.Build());

                throw new ConfigurationErrorsException(message);
            }

            await _diagnosticService.EmitAsync(
                new DiagnosticEventBuilder(this, DiagnosticEventType.ComponentInitialization)
            {
                Detail = "Initializing diagnostic event sink '" + myConfig.Name + "'"
            }.Build());

            var sink = await provider.CreateDiagnosticEventSink(myConfig);

            var filterSpec = new DiagnosticEventLevelSpecification(myConfig.MinLevel, myConfig.MaxLevel);
            var filterSink = new FilteringSink(sink, filterSpec);

            await _diagnosticService.EmitAsync(
                new DiagnosticEventBuilder(this, DiagnosticEventType.ComponentInitialization)
            {
                Detail = "Diagnostic event sink '" + myConfig.Name + "' initialized"
            }.Build());

            return(filterSink);
        }
        protected void WhenEvaluating()
        {
            var spec = new DiagnosticEventLevelSpecification(MinLevel, MaxLevel);

            IsSatisfied = spec.IsSatisfiedBy(Event);
        }