コード例 #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("Starting worker for sending log to Saturn at endpoint " + _options.CurrentValue.SaturnEndpoint);
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Waiting to read log from channel");
                try
                {
                    while (await _channel.GetChannel().Reader.WaitToReadAsync())
                    {
                        using var call = _client.Push();
                        if (_channel.GetChannel().Reader.TryRead(out LogCollectorRequest log))
                        {
                            await call.RequestStream.WriteAsync(log);
                        }
                        await call.RequestStream.CompleteAsync();

                        var serverResponse = await call.ResponseAsync;
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError("There are some problems when trying to stream log collector", ex.ToString());
                }
            }
        }
コード例 #2
0
 public async Task PushLog(LogCollectorRequest logCollectorRequest)
 {
     if (_loggerOptions.CurrentValue.NotifyOptions.Enable)
     {
         logCollectorRequest.ServiceId   = serviceId;
         logCollectorRequest.ServiceName = _serviceOptions.CurrentValue.Name;
         try
         {
             while (await _logCollectorChannel.GetChannel().Writer
                    .WaitToWriteAsync()
                    .ConfigureAwait(false))
             {
                 _logCollectorChannel.GetChannel().Writer.TryWrite(logCollectorRequest);
             }
         }
         catch (Exception ex)
         {
             throw new Exception("There are some erros when trying to notify log behavior in Service Management, please check stack trace.", ex);
         }
     }
 }