Ejemplo n.º 1
0
        public ScaniiClientTests()
        {
            var serilogLogger = new LoggerConfiguration()
                                .WriteTo.Console()
                                .MinimumLevel.Is(LogEventLevel.Debug)
                                .CreateLogger();

            var provider = new SerilogLoggerProvider(serilogLogger);

            _logger = provider.CreateLogger("ScaniiClientTests");

            _logger.LogDebug("ctor");


            if (Environment.GetEnvironmentVariable("SCANII_CREDS") != null)
            {
                // ReSharper disable once PossibleNullReferenceException
                var credentials = Environment.GetEnvironmentVariable("SCANII_CREDS").Split(':');
                _key    = credentials[0];
                _secret = credentials[1];
            }

            Debug.Assert(_secret != null, nameof(_secret) + " != null");
            Debug.Assert(_key != null, nameof(_key) + " != null");

            _client = ScaniiClients.CreateDefault(_key, _secret, _logger, new HttpClient());
        }
 public ILogger CreateLogger
 (
     string categoryName
 )
 {
     return(_provider.CreateLogger(categoryName));
 }
        private Tuple <SerilogLogger, SerilogSink> SetUp(LogLevel logLevel)
        {
            var sink = new SerilogSink();

            var l = new global::Serilog.Core.Logger(new global::Serilog.Core.LoggingLevelSwitch(logLevel), sink, new EmptyEnricher());

            var provider = new SerilogLoggerProvider(l);
            var logger   = (SerilogLogger)provider.CreateLogger(Name);

            return(new Tuple <SerilogLogger, SerilogSink>(logger, sink));
        }
        private Tuple <SerilogLogger, SerilogSink> SetUp(LogLevel logLevel)
        {
            var sink = new SerilogSink();

            var config = new LoggerConfiguration()
                         .WriteTo.Sink(sink);

            SetMinLevel(config, logLevel);

            var provider = new SerilogLoggerProvider(config.CreateLogger());
            var logger   = (SerilogLogger)provider.CreateLogger(Name);

            return(new Tuple <SerilogLogger, SerilogSink>(logger, sink));
        }
        static Tuple <SerilogLogger, SerilogSink> SetUp(LogLevel logLevel)
        {
            var sink = new SerilogSink();

            var serilogLogger = new LoggerConfiguration()
                                .WriteTo.Sink(sink)
                                .MinimumLevel.Is(LevelConvert.ToSerilogLevel(logLevel))
                                .CreateLogger();

            var provider = new SerilogLoggerProvider(serilogLogger);
            var logger   = (SerilogLogger)provider.CreateLogger(Name);

            return(new Tuple <SerilogLogger, SerilogSink>(logger, sink));
        }
Ejemplo n.º 6
0
        private Tuple <SerilogLogger, SerilogSink> SetUp(LogLevel logLevel)
        {
            var sink = new SerilogSink();

            var config = new LoggerConfiguration()
                         .WriteTo.Sink(sink);

            SetMinLevel(config, logLevel);

#pragma warning disable CA2000 // Dispose objects before losing scope
            var provider = new SerilogLoggerProvider(config.CreateLogger());
#pragma warning restore CA2000 // Dispose objects before losing scope
            var logger = (SerilogLogger)provider.CreateLogger(Name);

            return(new Tuple <SerilogLogger, SerilogSink>(logger, sink));
        }
Ejemplo n.º 7
0
        private Tuple <SerilogLogger, SerilogSink> SetUp(LogLevel logLevel)
        {
            var sink = new SerilogSink();

            var config = new LoggerConfiguration()
                         .Enrich.WithMachineName()
                         .Enrich.WithProcessId()
                         .Enrich.WithThreadId()
                         .WriteTo.Sink(sink);

            SetMinLevel(config, logLevel);

            var provider = new SerilogLoggerProvider(config.CreateLogger());
            var logger   = (SerilogLogger)provider.CreateLogger(_name);

            return(new Tuple <SerilogLogger, SerilogSink>(logger, sink));
        }
        private Tuple<SerilogLogger, SerilogSink> SetUp(LogLevel logLevel)
        {
            var sink = new SerilogSink();

            var config = new LoggerConfiguration()
                .Enrich.WithMachineName()
                .Enrich.WithProcessId()
                .Enrich.WithThreadId()
                .WriteTo.Sink(sink);

            SetMinLevel(config, logLevel);

            var provider = new SerilogLoggerProvider(config.CreateLogger());
            var logger = (SerilogLogger)provider.CreateLogger(Name);

            return new Tuple<SerilogLogger, SerilogSink>(logger, sink);
        }
        public HttpRequestActivityTests()
        {
            _httpContext = new DefaultHttpContext();
            _httpContext.Features.Set <IHttpResponseFeature>(_responseFeature = new TestResponseFeature());

            Logger serilog = new LoggerConfiguration()
                             .MinimumLevel.Verbose()
                             .WriteTo.TestCorrelator()
                             .CreateLogger();

            var serilogProvider = new SerilogLoggerProvider(serilog);

            _logger = serilogProvider.CreateLogger("");

            _sut = new HttpRequestActivity(_logger, _httpContext, CorrelationHttpHeaders.CorrelationId);
            _correlationContext = new CorrelationContext
            {
                CorrelationId = Guid.NewGuid().ToString()
            };
        }
        public CorrelationManagerTests()
        {
            _correlationContextAccessor = new CorrelationContextAccessor();

            _correlationIdFactoryMock = new Mock <ICorrelationIdFactory>();
            _correlationIdFactoryMock
            .Setup(m => m.Create())
            .Returns(() => GeneratedCorrelationId)
            .Verifiable();

            Logger serilogLogger = new LoggerConfiguration()
                                   .WriteTo.TestCorrelator()
                                   .CreateLogger();

            _logProvider = new SerilogLoggerProvider(serilogLogger);
            _logger      = new TestLogger <CorrelationManager>(_logProvider.CreateLogger(nameof(CorrelationManager)));

            _sut = new CorrelationManager(
                new CorrelationContextFactory(_correlationContextAccessor),
                _correlationIdFactoryMock.Object,
                _correlationContextAccessor,
                _logger
                );
        }
 /// <summary>
 /// Creates a new <see cref="T:Microsoft.Extensions.Logging.ILogger" /> instance.
 /// </summary>
 /// <param name="categoryName">The category name for messages produced by the logger.</param>
 /// <returns>
 /// The <see cref="T:Microsoft.Extensions.Logging.ILogger" />.
 /// </returns>
 public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName)
 {
     return(_provider.CreateLogger(categoryName));
 }
Ejemplo n.º 12
0
 ILogger ILoggerFactory.CreateLogger(string categoryName)
 {
     return(_loggerProvider.CreateLogger(categoryName));
 }
Ejemplo n.º 13
0
 ILogger ILoggerFactory.CreateLogger(string categoryName)
 {
     return(_additionalLoggerProviders.Count > 0
         ? new TestLogger(new [] { _loggerProvider }.Concat(_additionalLoggerProviders).Select(z => z.CreateLogger(categoryName)))
         : _loggerProvider.CreateLogger(categoryName));
 }
Ejemplo n.º 14
0
 public static ILogger GetLogger <T>()
 {
     CheckInit();
     return(_loggerProvider.CreateLogger(TypeNameHelper.GetTypeDisplayName(typeof(T))));
 }
Ejemplo n.º 15
0
 /// <summary>
 ///     Creates a new <see cref="T:Microsoft.Extensions.Logging.ILogger" /> instance.
 /// </summary>
 /// <param name="categoryName">The category name for messages produced by the logger.</param>
 /// <returns>
 ///     The <see cref="T:Microsoft.Extensions.Logging.ILogger" />.
 /// </returns>
 public ILogger CreateLogger(string categoryName) => _provider.CreateLogger(categoryName);