Skip to content

Instantly share code, notes, and snippets.

@stimms
Created September 29, 2016 14:57
Show Gist options
  • Save stimms/5f176972ca39ff45efdd41b33a28dac9 to your computer and use it in GitHub Desktop.
Save stimms/5f176972ca39ff45efdd41b33a28dac9 to your computer and use it in GitHub Desktop.
using Completions.Common.Logging;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Completions.MvcApplication.Features
{
public class LoggingMediator : IMediator
{
private readonly Mediator _mediator;
private readonly ILog _logger;
public LoggingMediator(SingleInstanceFactory singleInstanceFactory, MultiInstanceFactory multiInstanceFactory, ILog logger)
{
_logger = logger;
_mediator = new Mediator(singleInstanceFactory, multiInstanceFactory);
}
public void Publish(INotification notification)
{
_logger.Debug("Publishing {@notification} for {UserName}", notification);
_mediator.Publish(notification);
}
public Task PublishAsync(IAsyncNotification notification)
{
_logger.Debug("Publishing {@notification} for {UserName}", notification);
return _mediator.PublishAsync(notification);
}
public Task PublishAsync(ICancellableAsyncNotification notification, CancellationToken cancellationToken)
{
_logger.Debug("Publishing {@notification} for {UserName}", notification);
return _mediator.PublishAsync(notification, cancellationToken);
}
public TResponse Send<TResponse>(IRequest<TResponse> request)
{
_logger.Debug("Sending {@request} for {UserName}", request);
return _mediator.Send<TResponse>(request);
}
public Task<TResponse> SendAsync<TResponse>(IAsyncRequest<TResponse> request)
{
_logger.Debug("Sending async {@request} for {UserName}", request);
return _mediator.SendAsync<TResponse>(request);
}
public Task<TResponse> SendAsync<TResponse>(ICancellableAsyncRequest<TResponse> request, CancellationToken cancellationToken)
{
_logger.Debug("Sending async {@request} for {UserName}", request);
return _mediator.SendAsync<TResponse>(request, cancellationToken);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment