// method called when program booting public Task StartAsync(CancellationToken cancellationToken) { try { // create exchange , queue and bind queue with exchange Register(ExchangeName, QueueName, ExchangeArgu, ExchangeType); if (_timer != null) { _timer.Dispose(); } return(Task.CompletedTask); } catch (Exception ex) { _logger.LogError(ex, "failure when try register {CreationDate} {ExchangeName} {QueueName}", DateTime.Now, ExchangeName, QueueName); //retry to connect _timer = new System.Timers.Timer(); // 2 minute _timer.Interval = 120000; _timer.Elapsed += _timer_Elapsed; _timer.Start(); return(Task.CompletedTask); } }
public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next) { try { return(await next()); } catch (ValidationException) { _logger.LogWarning("{Status} {ReferenceNumber}", MessageLifeCycle.ValidationError, _referenceNumberService.ReferenceNumber); throw; } catch (Exception ex) { _logger.LogError(ex, MessageLifeCycle.ExceptoinWhenProcessNewRequest, _referenceNumberService.ReferenceNumber); throw; } }
private void OnConnectionBlocked(object sender, ConnectionBlockedEventArgs e) { _logger.LogError("ConnectionBlocked {CreationDate} {e}", DateTime.Now, Newtonsoft.Json.JsonConvert.SerializeObject(e)); }