Ejemplo n.º 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            try
            {
                if (!_serviceEnabled)
                {
                    _logger.LogInformation("Telemetry service is disabled!");
                    return;
                }

                if (_telemetryPublisher == null)
                {
                    _logger?.LogCritical("Invalid state! TelemetryPublisher is null!");
                    return;
                }

                await Task.Delay(_interval, stoppingToken);

                while (!stoppingToken.IsCancellationRequested)
                {
                    await _telemetryPublisher.PublishAsync(stoppingToken);

                    _logger?.LogDebug("Telemetry data published!");
                    await Task.Delay(_interval, stoppingToken);
                }
            }
            catch (TaskCanceledException)
            {
                _logger?.LogInformation("The TelemetryWorker task was canceled.");
            }
            catch (Exception e)
            {
                _logger?.LogError($"Unhandled exception in TelemetryWorker. {e.Message}");
                _logger?.LogDebug(e.StackTrace);
            }
        }
Ejemplo n.º 2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            if (!_serviceEnabled)
            {
                _logger.LogInformation("Telemetry service is disabled!");
                return;
            }

            if (_telemetryPublisher == null)
            {
                _logger?.LogCritical("Invalid state! TelemetryPublisher is null!");
                return;
            }

            await Task.Delay(_interval, stoppingToken);

            while (!stoppingToken.IsCancellationRequested)
            {
                await _telemetryPublisher.PublishAsync(stoppingToken);

                _logger?.LogDebug("Telemetry data published!");
                await Task.Delay(_interval, stoppingToken);
            }
        }