Exemple #1
0
        public void Setup()
        {
            var host = Host.CreateDefaultBuilder()
                       .UseSerilog((context, configuration) =>
            {
                configuration
                .MinimumLevel.Verbose()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.Console();
            })
                       .ConfigureHostConfiguration(builder => builder.AddEnvironmentVariables())
                       .UseSimpleBotFramework((builder, context) =>
            {
                builder.UseStaticCommands(new StaticCommandsList(new[]
                {
                    typeof(CancelCommand),
                    typeof(StatefullCommand)
                }));
            }, true)
                       .Build();

            client = host.Services.GetService <AppUpdateProducer>();
            _sink  = host.Services.GetService <IRequestSinc>() as MemorySink;
        }
        public BackgroundWorkerSinkSpec()
        {
            _innerSink = new MemorySink();
            var logger = new LoggerConfiguration().WriteTo.Sink(_innerSink).CreateLogger();

            _sink = new BackgroundWorkerSink(logger, 10000);
        }
        public void Setup()
        {
            var logger = new LoggerConfiguration().MinimumLevel.Verbose()
                         .WriteTo.Console()
                         .CreateLogger();

            _sink = new MemorySink(logger);
        }
        static List <LogEvent> RetrieveEvents(MemorySink sink, int count)
        {
            Debug.WriteLine("{0:h:mm:ss tt} Retrieving {1} events", DateTime.Now, count);

            Loop.Retry(() => sink.Events, events => events != null && events.Count >= count, TimeSpan.FromSeconds(1),
                       TimeSpan.FromSeconds(30));

            return(sink.Events.ToList());
        }
Exemple #5
0
        public void DisposeCompletesWithoutWorkPerformed()
        {
            var collector = new MemorySink();

            using (new LoggerConfiguration()
                   .WriteTo.Async(w => w.Sink(collector))
                   .CreateLogger())
            {
            }

            Assert.Empty(collector.Events);
        }
Exemple #6
0
        public void EventsArePassedToInnerSink()
        {
            var collector = new MemorySink();

            using (var log = new LoggerConfiguration()
                             .WriteTo.Async(w => w.Sink(collector))
                             .CreateLogger())
            {
                log.Information("Hello, async world!");
                log.Information("Hello again!");
            }

            Assert.Equal(2, collector.Events.Count);
        }
Exemple #7
0
        public void CtorAndDisposeInformMonitor()
        {
            var collector = new MemorySink();
            var monitor   = new DummyMonitor();

            using (new LoggerConfiguration()
                   .WriteTo.Async(w => w.Sink(collector), monitor: monitor)
                   .CreateLogger())
            {
                Assert.NotNull(monitor.Inspector);
            }

            Assert.Null(monitor.Inspector);
        }
Exemple #8
0
        public void Setup()
        {
            var host = Host.CreateDefaultBuilder()
                       .UseSerilog((context, configuration) =>
            {
                configuration
                .MinimumLevel.Debug()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.Console();
            })
                       .ConfigureHostConfiguration(builder => builder.AddEnvironmentVariables())
                       .UseSimpleBotFramework(
                (builder, context) => { builder.UseStaticCommandsAssembly(typeof(HelpCommand).Assembly); }, true)
                       .Build();

            producer = host.Services.GetService <AppUpdateProducer>();
            _sink    = host.Services.GetService <IRequestSinc>() as MemorySink;
        }
        public void MonitorParameterAffordsSinkInspectorSuitableForHealthChecking()
        {
            var collector = new MemorySink {
                DelayEmit = TimeSpan.FromSeconds(2)
            };
            // 2 spaces in queue; 1 would make the second log entry eligible for dropping if consumer does not activate instantaneously
            var bufferSize = 2;
            var monitor    = new DummyMonitor();

            using (var logger = new LoggerConfiguration()
                                .WriteTo.Async(w => w.Sink(collector), bufferSize: 2, monitor: monitor)
                                .CreateLogger())
            {
                // Construction of BackgroundWorkerSink triggers StartMonitoring
                var inspector = monitor.Inspector;
                Assert.Equal(bufferSize, inspector.BufferSize);
                Assert.Equal(0, inspector.Count);
                Assert.Equal(0, inspector.DroppedMessagesCount);
                logger.Information("Something to freeze the processing for 2s");
                // Can be taken from queue either instantanously or be awaiting consumer to take
                Assert.InRange(inspector.Count, 0, 1);
                Assert.Equal(0, inspector.DroppedMessagesCount);
                logger.Information("Something that will sit in the queue");
                Assert.InRange(inspector.Count, 1, 2);
                logger.Information("Something that will probably also sit in the queue (but could get dropped if first message has still not been picked up)");
                Assert.InRange(inspector.Count, 1, 2);
                logger.Information("Something that will get dropped unless we get preempted for 2s during our execution");
                const string droppedMessage = "Something that will definitely get dropped";
                logger.Information(droppedMessage);
                Assert.InRange(inspector.Count, 1, 2);
                // Unless we are put to sleep for a Rip Van Winkle period, either:
                // a) the BackgroundWorker will be emitting the item [and incurring the 2s delay we established], leaving a single item in the buffer
                // or b) neither will have been picked out of the buffer yet.
                Assert.InRange(inspector.Count, 1, 2);
                Assert.Equal(bufferSize, inspector.BufferSize);
                Assert.DoesNotContain(collector.Events, x => x.MessageTemplate.Text == droppedMessage);
                // Because messages wait 2 seconds, the only real way to get one into the buffer is with a debugger breakpoint or a sleep
                Assert.InRange(collector.Events.Count, 0, 3);
            }
            // Dispose should trigger a StopMonitoring call
            Assert.Null(monitor.Inspector);
        }
            protected SinkSpecBase(bool useBufferedQueue, bool delayCreation)
            {
                _delayCreation = delayCreation;

                _memorySink = new MemorySink();

                if (useBufferedQueue)
                {
                    _logger = new LoggerConfiguration()
                              .WriteTo.Async(a => a.Sink(_memorySink))
                              .CreateLogger();
                }
                else
                {
                    _logger = new LoggerConfiguration()
                              .WriteTo.Sink(_memorySink)
                              .CreateLogger();
                }

                Debug.WriteLine("{0:h:mm:ss tt} Started test", DateTime.Now);
            }
        /// <summary>
        /// Write log events to the provided <see cref="Queue{T}"/>.
        /// </summary>
        /// <param name="sinkConfiguration">Logger sink configuration.</param>
        /// <param name="messagesQueue">The queue to write log events to.</param>
        /// <param name="messagesCountLimit">The maximum of number of messages to keep</param>
        /// <param name="formatter">Text formatter used by sink.</param>
        /// /// <param name="restrictedToMinimumLevel">The minimum level for
        /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
        /// <param name="levelSwitch">A switch allowing the pass-through minimum level
        /// to be changed at runtime.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public static LoggerConfiguration MemoryWriter(
            this LoggerSinkConfiguration sinkConfiguration,
            ITextFormatter formatter,
            Queue <string> messagesQueue,
            int messagesCountLimit,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            LoggingLevelSwitch levelSwitch         = null)
        {
            if (messagesQueue == null)
            {
                throw new ArgumentNullException(nameof(messagesQueue));
            }
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }

            var sink = new MemorySink(messagesQueue, formatter, messagesCountLimit);

            return(sinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch));
        }
Exemple #12
0
        public ActionResult GetLogs(
            [FromQuery(Name = "start")] DateTimeOffset start,
            [FromQuery(Name = "end")] DateTimeOffset end,
            ApiVersion apiVersion)
        {
            LogListDto logsDto = new LogListDto
            {
                start = start,
                end   = end,
                Logs  = MemorySink
                        .GetInstance()
                        .GetLogs(start, end)
                        .Select(logEvent =>
                                new LogDto
                {
                    Timestamp = logEvent.Timestamp,
                    Message   = logEvent.RenderMessage(),
                    Level     = logEvent.Level.ToString()
                })
                        .OrderBy(logDto => logDto.Timestamp),
            };

            return(Ok(logsDto.WithLinks(Url, apiVersion)));
        }
        public void Setup()
        {
            _userRepository = new Mock <IUserRepository <IdentityUser> >();

            var host = Host.CreateDefaultBuilder()
                       .UseSerilog((context, configuration) =>
            {
                configuration
                .MinimumLevel.Debug()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.Console();
            })
                       .ConfigureHostConfiguration(builder => builder.AddEnvironmentVariables())
                       .UseSimpleBotFramework((builder, context) =>
            {
                builder.UseIdentity <IdentityUser>();
                builder.Services.AddSingleton(provider => _userRepository.Object);
            }, true)
                       .Build();

            client = host.Services.GetService <AppUpdateProducer>();
            _sink  = host.Services.GetService <IRequestSinc>() as MemorySink;
        }
 public static SinkSubscription<MemorySink> LogToMemory(
 this IObservable<EventEntry> eventStream, ref List<string> log) {
     var sink = new MemorySink(ref log);
     var subscription = eventStream.Subscribe(sink);
     return new SinkSubscription<MemorySink>(subscription, sink);
 }