public async Task <CommandResult <TResult> > DispatchAsync <TResult>(ICommand <TResult> command, CancellationToken cancellationToken = new CancellationToken()) { IMetricCollector metricCollector = _metricCollectorFactory.Create(command.GetType()); try { LogPreDispatchMessage(command); CommandResult <TResult> result = await _underlyingDispatcher.DispatchAsync(command, cancellationToken); LogSuccessfulPostDispatchMessage(command); metricCollector.Complete(); return(result); } catch (Exception ex) { LogFailedPostDispatchMessage(command, ex); metricCollector.CompleteWithError(); throw new DispatcherException($"Error occurred performing operation {command.GetType().Name}", ex); } }