Exemplo n.º 1
3
        public void WriteLog(ICorrelation correlation, LogEventLevel eventLevel, Exception exception, string formatMessage, params object[] args)
        {
            if (log == null)
            {
                log = loggerRepository.GetLogger(sourceType);
            }

            if (eventLevel == LogEventLevel.Verbose && !log.IsDebugEnabled)
            {
                return;
            }

            if (args != null && args.Length != 0)
            {
                formatMessage = string.Format(formatMessage, args);
            }

            log4net.Core.ILogger logger = log.Logger;

            LoggingEvent logEvent = new LoggingEvent(sourceType, logger.Repository, logger.Name, MapEventLevel(eventLevel), formatMessage, exception);

            if (correlation != null)
            {
                logEvent.Properties["CallerId"] = correlation.CallerId;
                logEvent.Properties["CorrelationId"] = correlation.CorrelationId;
            }

            logger.Log(logEvent);
        }
 protected EventHandler(ILogger log, ICorrelation correlation, ISendCommand commandSender, ISendQuery querySender)
 {
     Log            = log;
     Correlation    = correlation;
     _commandSender = commandSender;
     _querySender   = querySender;
 }
 public TestProcessManager(IMetricsService metricsService, ISession session, ICorrelation correlation, IClock clock)
 {
     _metricsService = metricsService;
     _session        = session;
     _correlation    = correlation;
     _clock          = clock;
 }
        protected void SetCorrelation(string requestId, ICorrelation originalCorrelation)
        {
            _correlation.CorrelationId = originalCorrelation.CorrelationId ?? Guid.NewGuid().ToString();
            _correlation.CausationId   = originalCorrelation.CurrentId;
            _correlation.CurrentId     = requestId;

            _log.ForContext("correlation", _correlation, true).Debug("Correlation in loopback scope updated from parent");
        }
Exemplo n.º 5
0
 public RequestLoggingMiddleware(ILoggerFactory loggerFactory, ICorrelation correlation)
     : this(loggerFactory, correlation,
            new LoggingMiddlewareConfiguration(
                LogEventLevel.Information,
                "Incoming request - {Method}: {Path}, {Headers}",
                context => new object[] { context.Request.Method, context.Request.Path.Value, context.Request.Headers }))
 {
 }
Exemplo n.º 6
0
 public ResponseLoggingMiddleware(ILoggerFactory loggerFactory, ICorrelation correlation)
     : this(loggerFactory, correlation,
            new LoggingMiddlewareConfiguration(
                LogEventLevel.Information,
                "Outgoing response - {StatusCode}, {Headers}",
                context => new object[] { context.Response.StatusCode, context.Request.Headers }))
 {
 }
        public void Setup()
        {
            loggerFactory = Substitute.For<ILoggerFactory>();
            logger = Substitute.For<ICorrelationLogger>();
            loggerFactory.CreateCorrelationLogger(Arg.Any<RequestErrorLogger>()).Returns(logger);
            correlation = Substitute.For<ICorrelation>();

            sut = new RequestErrorLogger(loggerFactory, request => correlation);
        }
Exemplo n.º 8
0
        public Log(ICorrelation correlation)
        {
            if (_logging == null)
            {
                _logging = NLog.LogManager.GetCurrentClassLogger();
            }

            _correlation = correlation;
        }
Exemplo n.º 9
0
        public void Setup()
        {
            loggerFactory = Substitute.For <ILoggerFactory>();
            logger        = Substitute.For <ICorrelationLogger>();
            loggerFactory.CreateCorrelationLogger(Arg.Any <RequestErrorLogger>()).Returns(logger);
            correlation = Substitute.For <ICorrelation>();

            sut = new RequestErrorLogger(loggerFactory, request => correlation);
        }
        public RequestLoggingFilter(ILoggerFactory loggerFactory, ICorrelation correlation = null)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException("loggerFactory");
            }

            logger = loggerFactory.CreateCorrelationLogger(this);
            this.correlation = correlation;
        }
Exemplo n.º 11
0
        public async Task PublishAsync(IEnumerable <IEvent> events, ICorrelation correlation, CancellationToken cancellationToken = default)
        {
            await using var scope = _scope.BeginLifetimeScope();
            var receiver = scope.Resolve <IReceiveLoopbackEvent>();

            foreach (IEvent @event in events)
            {
                await receiver.ReceiveAsync(@event, correlation, cancellationToken);
            }
        }
Exemplo n.º 12
0
        public RequestLoggingFilter(ILoggerFactory loggerFactory, ICorrelation correlation = null)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException("loggerFactory");
            }

            logger           = loggerFactory.CreateCorrelationLogger(this);
            this.correlation = correlation;
        }
Exemplo n.º 13
0
 public void Setup()
 {
     context = new HttpActionContext(new HttpControllerContext(new HttpRequestContext(), new HttpRequestMessage(), new HttpControllerDescriptor(), Substitute.For <IHttpController>()),
                                     new ReflectedHttpActionDescriptor());
     loggerFactory = Substitute.For <ILoggerFactory>();
     logger        = Substitute.For <ICorrelationLogger>();
     loggerFactory.CreateCorrelationLogger(Arg.Any <RequestLoggingFilter>()).Returns(logger);
     correlation = Substitute.For <ICorrelation>();
     sut         = new RequestLoggingFilter(loggerFactory, correlation);
 }
Exemplo n.º 14
0
        protected LoggingMiddleware(ILoggerFactory loggerFactory, ICorrelation correlation)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            logger           = loggerFactory.CreateCorrelationLogger(this);
            this.correlation = correlation ?? throw new ArgumentNullException(nameof(correlation));
        }
Exemplo n.º 15
0
        public static HttpConfiguration ConfigureIoc(this HttpConfiguration config)
        {
            var container = Initialize()
                            .ResolveSingleton()
                            .ResolveWebRequest();

            config.DependencyResolver = new UnityConfig.UnityResolver(container);

            ILog driver = container.Resolve <ILog>();

            ICorrelation correlationDriver = container.Resolve <ICorrelation>();
            IBasicRequestDataProvider basicRequestDriver = container.Resolve <IBasicRequestDataProvider>();

            config.MessageHandlers.Add(new CorrelationHandler(correlationDriver, basicRequestDriver));
            config.MessageHandlers.Add(new CustomLogHandler(driver));

            return(config);
        }
 public async Task ReceiveAsync <T>(T @event, ICorrelation correlation, CancellationToken cancellationToken = default) where T : IEvent
 {
     SetCorrelation(@event.EventId, correlation);
     await _next.ReceiveAsync(@event, correlation, cancellationToken);
 }
 protected CommandHandlerBase(ILogger log, ICorrelation correlation, ISendQuery querySender)
 {
     Correlation  = correlation;
     _querySender = querySender;
     Log          = log;
 }
Exemplo n.º 18
0
        } // TraceAffinity

        public void TraceCorrelations(ICorrelation correlation)
        {
            Correlation = correlation;
        } // TraceCorrelations
Exemplo n.º 19
0
        private void AssertCall(ICorrelation expectedCorrelation, LogEventLevel eventLevel, Exception exception, string formatMessage,
            object[] args)
        {
            Assert.AreEqual(1, logWriter.ReceivedCalls().Count());

            ICall call = logWriter.ReceivedCalls().First();
            object[] arguments = call.GetArguments();

            Assert.AreEqual(5, arguments.Length);

            if (expectedCorrelation == null)
            {
                Assert.IsNull(arguments[0]);
            }
            else
            {
                ICorrelation actualCorrelation = arguments[0] as ICorrelation;
                Assert.IsNotNull(actualCorrelation);

                if (!string.IsNullOrEmpty(expectedCorrelation.CallerId))
                {
                    Assert.AreEqual(expectedCorrelation.CallerId, actualCorrelation.CallerId);
                }

                if (!string.IsNullOrEmpty(expectedCorrelation.CorrelationId))
                {
                    Assert.AreEqual(expectedCorrelation.CorrelationId, actualCorrelation.CorrelationId);
                }
            }

            Assert.AreEqual(eventLevel, arguments[1]);
            Assert.AreEqual(exception, arguments[2]);
            Assert.AreEqual(formatMessage, arguments[3]);

            object[] messageParams = arguments[4] as object[];

            Assert.IsNotNull(messageParams);
            Assert.AreEqual(args.Length, messageParams.Length);

            for (int i = 0; i < messageParams.Length; i++)
            {
                Assert.AreEqual(args[i], messageParams[i]);
            }
        }
Exemplo n.º 20
0
 public ResponseLoggingMiddleware(ILoggerFactory loggerFactory, ICorrelation correlation, LoggingMiddlewareConfiguration configuration)
     : base(loggerFactory, correlation)
 {
     this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
 public async Task SendAsync <TCommand>(TCommand command, ICorrelation correlation, CancellationToken cancellationToken = default) where TCommand : ICommand
 {
     await using var scope = _scope.BeginLifetimeScope();
     await scope.Resolve <IReceiveLoopbackCommand>().ReceiveAsync(command, correlation, cancellationToken);
 }
 public HttpEventPublisherCorrelationBehavior(ILogger log, ICorrelation correlation, IOptions <HttpRequestOptions> options, IPublishHttpEvent next) : base(log, correlation, options)
 {
     _next = next;
 }
Exemplo n.º 23
0
 public TestQueryHandler(ILogger log, ICorrelation correlation, ISendQuery querySender) : base(log, correlation, querySender)
 {
 }
Exemplo n.º 24
0
 public void LogWarning(ICorrelation correlation, string formatMessage, params object[] args)
 {
     LogWarning(correlation, null, formatMessage, args);
 }
Exemplo n.º 25
0
 public void LogError(ICorrelation correlation, Exception exception, string formatMessage, params object[] args)
 {
     logWriter.WriteLog(correlation, LogEventLevel.Error, exception, formatMessage, args);
 }
 public async Task <TResult> ReceiveAsync <TResult>(IQuery <TResult> query, ICorrelation correlation, CancellationToken cancellationToken = default)
 {
     SetCorrelation(query.QueryId, correlation);
     return(await _next.ReceiveAsync(query, correlation, cancellationToken));
 }
Exemplo n.º 27
0
 protected CommandHandler(ILogger log, ICorrelation correlation, ISendQuery querySender, IPublishEvent eventPublisher) : base(log, correlation, querySender)
 {
     _eventPublisher = eventPublisher;
 }
Exemplo n.º 28
0
 protected QueryHandler(ILogger log, ICorrelation correlation, ISendQuery querySender)
 {
     _querySender = querySender;
     Log          = log;
     Correlation  = correlation;
 }
Exemplo n.º 29
0
 public CorrelationHandler(ICorrelation correlation, IBasicRequestDataProvider basicRequestDataProvider)
 {
     _basicRequestDataProvider = basicRequestDataProvider;
     _correlation = correlation;
 }
Exemplo n.º 30
0
        public void Setup()
        {
            correlation = new Correlation(CorrelationId, CallerId);
            log = Substitute.For<ILog>();
            logger = Substitute.For<log4net.Core.ILogger>();
            log.Logger.Returns(logger);

            repository = Substitute.For<ILoggerRepository>();
            repository.GetLogger(source.GetType()).Returns(log);

            sut = new LogWriter(repository, source);
        }
Exemplo n.º 31
0
 public PerformanceLoggingMiddleware(ILoggerFactory loggerFactory, ICorrelation correlation)
     : base(loggerFactory, correlation)
 {
 }
Exemplo n.º 32
0
 public void LogVerbose(ICorrelation correlation, string formatMessage, params object[] args)
 {
     logWriter.WriteLog(correlation, LogEventLevel.Verbose, null, formatMessage, args);
 }
 public TestEventHandler2(ILogger log, ICorrelation correlation, ISendCommand commandSender, ISendQuery querySender) : base(log, correlation, commandSender, querySender)
 {
 }
 public async Task <TResult> ReceiveAsync <TResult>(IQuery <TResult> query, ICorrelation correlation, CancellationToken cancellationToken = default)
 {
     return(await _receiver.ReceiveAsync(query, cancellationToken));
 }
 public async Task <TResult> SendAsync <TResult>(IQuery <TResult> query, ICorrelation correlation, CancellationToken cancellationToken = default)
 {
     await using var scope = _scope.BeginLifetimeScope();
     return(await scope.Resolve <IReceiveLoopbackQuery>().ReceiveAsync(query, correlation, cancellationToken));
 }
Exemplo n.º 36
0
 public void Setup()
 {
     logWriter = Substitute.For<ILogWriter>();
     correlation = Substitute.For<ICorrelation>();
     sut = new Logger(logWriter);
 }
 public RabbitCommandSenderCorrelationBehavior(ILogger log, IModel model, ICorrelation correlation, ISendRabbitCommand next) : base(log, correlation)
 {
     _next = next;
 }
 protected HttpSenderCorrelationBehavior(ILogger log, ICorrelation correlation, IOptions <HttpRequestOptions> options)
 {
     _log         = log;
     _correlation = correlation;
     _options     = options.Value;
 }
Exemplo n.º 39
0
 public TestCommand2Handler(ILogger log, ICorrelation correlation, ISendQuery querySender, IPublishEvent eventPublisher) : base(log, correlation, querySender, eventPublisher)
 {
 }