public Task StartAsync(CancellationToken cancellationToken) { try { _consumerHost.Start(); } catch (Exception e) { _log.Error("Error when starting consuming", e).Write(); } return(Task.CompletedTask); }
public async Task <FakeMessageQueueProcResult> Queue(object message, string queue, IBasicProperties messageProps = null) { if (!_consumers.TryGetValue(queue, out var consumer)) { return(null); } using var scope = _serviceProvider.CreateScope(); var msgAccessorCore = scope.ServiceProvider.GetService <IMqMessageAccessorCore>(); msgAccessorCore.SetScopedMessage(message, messageProps); var ctx = new FakeConsumingContext(message, _serviceProvider); try { await consumer.Consume(ctx); } catch (Exception e) { _log?.Error(e).Write(); } return(ctx.Result); }
public void OnException(ExceptionContext context) { HttpStatusCode actualResultCode; if (ErrorToResponseMap.GetFromActionProperties(context.ActionDescriptor.Properties, out var map) && map.TryGetBinding(context.Exception.GetType(), out var binding)) { actualResultCode = SetBoundResult(context, binding); } else { actualResultCode = SetErrorResult(context); } if ((int)actualResultCode >= 500) { _log.Error(context.Exception) .AndFactIs("response-code", actualResultCode) .AndFactIs(HttpTraceIdFact.Key, context.HttpContext.TraceIdentifier) .Write(); } else if ((int)actualResultCode >= 400) { _log.Warning(context.Exception) .AndFactIs("response-code", actualResultCode) .AndFactIs(HttpTraceIdFact.Key, context.HttpContext.TraceIdentifier) .Write(); } }
/// <summary> /// Begin DSL expression for error log-event /// </summary> public static DslExpression Error(this IDslLogger dslLogger, string message, Exception reasonException) { if (dslLogger == null) { throw new ArgumentNullException(nameof(dslLogger)); } return(dslLogger.Error(message).BecauseOf(reasonException)); }
private async Task Async() { _lastLogger.Debug("Start monitor task").Write(); do { await Task.Delay(TimeSpan.FromSeconds(1)); var lastMsgTimeDelta = DateTime.Now - _lastMsgTime; if (lastMsgTimeDelta >= BatchTimeout && _messages.Count != 0) { ApplyContext( _lastLogger.Debug("Hit mq batch processing"), lastMsgTimeDelta ) .Write(); try { await PerformConsumingAsync(); } catch (Exception e) { ApplyContext( _lastLogger.Error("Mq batch processing error", e), lastMsgTimeDelta ) .Write(); } } else { ApplyContext( _lastLogger.Debug("Pass mq batch processing"), lastMsgTimeDelta ) .Write(); } } while (true); DslExpression ApplyContext(DslExpression dslExpression, TimeSpan lastMsgTimeDelta) { return(dslExpression .AndLabel("async-mq-batch-processing") .AndFactIs("last-msg-time", _lastMsgTime.ToString("T")) .AndFactIs("last-msg-delta", lastMsgTimeDelta.ToString("T")) .AndFactIs("queue", Queue) .AndFactIs("msg-count", _messages.Count)); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { try { _statusService.LogicStarted(); await _logic.Perform(stoppingToken); _statusService.LogicCompleted(); } catch (Exception e) { _statusService.LogicError(e); _log?.Error("Error when perform task logic", e).Write(); } await Task.Delay(_period, stoppingToken); } }
public async System.Threading.Tasks.Task Execute(IJobExecutionContext context) { var opts = JobOptions.FromJobDataMap(context.JobDetail.JobDataMap); try { var kickOptions = new KickOptions(opts); var response = await _taskKickerService.KickAsync(kickOptions); _logger.Action("Task kicked") .AndFactIs("job-id", opts.Id) .AndFactIs("task-resp", response) .Write(); } catch (Exception e) { _logger.Error(e) .AndFactIs("job-id", opts.Id) .Write(); } }
private void ProcessException(object?sender, CallbackExceptionEventArgs e) { _logger .Error(e.Exception) .Write(); }
public DslExpression Error(string message) { return(ApplyExtensions(_dsl.Error(message))); }