コード例 #1
0
ファイル: HandlerTest.cs プロジェクト: pngouin/CK-Glouton
        public void handler_can_send_some_log()
        {
            using (var server = TestHelper.DefaultMockServer())
            {
                server.Open();

                using (var grandOutputServer = GrandOutputHelper.GetNewGrandOutputServer())
                    using (var grandOutputClient = GrandOutputHelper.GetNewGrandOutputClient())
                    {
                        var serverActivityMonitor = new ActivityMonitor {
                            MinimalFilter = LogFilter.Debug
                        };
                        grandOutputServer.EnsureGrandOutputClient(serverActivityMonitor);

                        var clientActivityMonitor = new ActivityMonitor {
                            MinimalFilter = LogFilter.Debug
                        };
                        grandOutputClient.EnsureGrandOutputClient(clientActivityMonitor);

                        var guid = Guid.NewGuid().ToString();
                        clientActivityMonitor.Info(guid);

                        Thread.Sleep(TestHelper.DefaultSleepTime);

                        server.GetLogEntry(guid).Validate(guid).Should().BeTrue();

                        serverActivityMonitor.CloseGroup();
                        clientActivityMonitor.CloseGroup();
                    }
            }
        }
コード例 #2
0
        public static void ConstructIndex()
        {
            if (_initialized)
            {
                return;
            }

            using (var server = TestHelper.DefaultGloutonServer())
            {
                server.Open(new HandlersManagerConfiguration
                {
                    GloutonHandlers = { LuceneGloutonHandlerConfiguration }
                });

                using (var grandOutputClient = GrandOutputHelper.GetNewGrandOutputClient())
                {
                    var activityMonitor = new ActivityMonitor(false)
                    {
                        MinimalFilter = LogFilter.Debug
                    };
                    grandOutputClient.EnsureGrandOutputClient(activityMonitor);

                    activityMonitor.Info("Hello world");
                    activityMonitor.Error("CriticalError");

                    TotalLogCount += 2;

                    activityMonitor.Fatal(ThrowAggregateException(3));
                }
            }
            _initialized = true;
        }
コード例 #3
0
        public void can_add_alert()
        {
            using (var server = TestHelper.DefaultGloutonServer())
            {
                server.Open(new HandlersManagerConfiguration
                {
                    GloutonHandlers =
                    {
                        new AlertHandlerConfiguration {
                            DatabasePath = @"%localappdata%/Glouton/Alerts".GetPathWithSpecialFolders()
                        }
                    }
                });

                using (var grandOutputClient = GrandOutputHelper.GetNewGrandOutputClient())
                {
                    var activityMonitor = new ActivityMonitor(false)
                    {
                        MinimalFilter = LogFilter.Debug
                    };
                    grandOutputClient.EnsureGrandOutputClient(activityMonitor);

                    using (var receiver = new SingleHttpReceiver(SingleHttpReceiver.DefaultUrl))
                    {
                        activityMonitor.Info("Hello world");
                        Thread.Sleep(TestHelper.DefaultSleepTime);
                        receiver.Alerted.Should().BeFalse();
                    }

                    server.ApplyConfiguration(new HandlersManagerConfiguration
                    {
                        GloutonHandlers =
                        {
                            new AlertHandlerConfiguration               {
                                DatabasePath = @"%localappdata%/Glouton/Alerts".GetPathWithSpecialFolders(),
                                Alerts       = new List <IAlertExpressionModel>
                                {
                                    new AlertExpressionModelMock
                                    (
                                        new []                          { new []                      { "Text", "EqualTo", "Hello world" } },
                                        new IAlertSenderConfiguration[] { new HttpSenderConfiguration {
                                                                              Url = SingleHttpReceiver.DefaultUrl
                                                                          } }
                                    )
                                }
                            }
                        }
                    });
                    Thread.Sleep(TestHelper.DefaultSleepTime);

                    using (var receiver = new SingleHttpReceiver(SingleHttpReceiver.DefaultUrl))
                    {
                        activityMonitor.Info("Hello world");
                        Thread.Sleep(TestHelper.DefaultSleepTime * 10);
                        receiver.Alerted.Should().BeTrue();
                    }
                }
            }
        }
コード例 #4
0
ファイル: HandlerTest.cs プロジェクト: pngouin/CK-Glouton
        public void close_and_reopen_server()
        {
            using (var server = TestHelper.DefaultMockServer())
            {
                server.Open();

                using (var grandOutputServer = GrandOutputHelper.GetNewGrandOutputServer())
                {
                    var serverActivityMonitor = new ActivityMonitor {
                        MinimalFilter = LogFilter.Debug
                    };
                    grandOutputServer.EnsureGrandOutputClient(serverActivityMonitor);

                    using (var grandOutputClient = GrandOutputHelper.GetNewGrandOutputClient())
                    {
                        var clientActivityMonitor = new ActivityMonitor {
                            MinimalFilter = LogFilter.Debug
                        };
                        grandOutputClient.EnsureGrandOutputClient(clientActivityMonitor);

                        var guid = Guid.NewGuid().ToString();

                        clientActivityMonitor.Info(guid);
                        Thread.Sleep(TestHelper.DefaultSleepTime);
                        server.GetLogEntry(guid).Validate(guid).Should().BeTrue();

                        serverActivityMonitor.Info("Closing the server");
                        server.Close();

                        server.ListLog.Clear();
                        clientActivityMonitor.Info(guid);
                        Thread.Sleep(TestHelper.DefaultSleepTime);
                        Action action = () => server.GetLogEntry(guid);
                        action.ShouldThrow <InvalidOperationException>();
                    }

                    serverActivityMonitor.Info("Reopening server");
                    server.Open();

                    using (var grandOutputClient = GrandOutputHelper.GetNewGrandOutputClient())
                    {
                        var clientActivityMonitor = new ActivityMonitor {
                            MinimalFilter = LogFilter.Debug
                        };
                        grandOutputClient.EnsureGrandOutputClient(clientActivityMonitor);

                        var guid = Guid.NewGuid().ToString();

                        server.ListLog.Clear();
                        clientActivityMonitor.Info(guid);
                        Thread.Sleep(TestHelper.DefaultSleepTime);
                        server.GetLogEntry(guid).Validate(guid).Should().BeTrue();
                    }
                }
            }
        }
コード例 #5
0
ファイル: HandlerTest.cs プロジェクト: pngouin/CK-Glouton
        public void handler_sends_multiple_logs()
        {
            using (var server = TestHelper.DefaultMockServer())
            {
                server.Open();

                using (var grandOutputServer = GrandOutputHelper.GetNewGrandOutputServer())
                    using (var grandOutputClient = GrandOutputHelper.GetNewGrandOutputClient())
                    {
                        var serverActivityMonitor = new ActivityMonitor {
                            MinimalFilter = LogFilter.Debug
                        };
                        grandOutputServer.EnsureGrandOutputClient(serverActivityMonitor);

                        var clientActivityMonitor = new ActivityMonitor {
                            MinimalFilter = LogFilter.Debug
                        };
                        grandOutputClient.EnsureGrandOutputClient(clientActivityMonitor);

                        const string initialMessage = "Hello";
                        const string debugMessage   = "This is the error";
                        const string traceMessage   = "Weird/trace/message";
                        const string warnMessage    = "You forgot something in the oven";
                        const string errorMessage   = "No, an error...";
                        const string fatalMessage   = "A fatal";
                        const string finalMessage   = "It's only a goodbye";

                        clientActivityMonitor.Info(initialMessage);
                        clientActivityMonitor.Debug(debugMessage);
                        clientActivityMonitor.Trace(traceMessage);
                        clientActivityMonitor.Warn(warnMessage);
                        clientActivityMonitor.Error(errorMessage);
                        clientActivityMonitor.Fatal(fatalMessage);
                        clientActivityMonitor.Info(finalMessage);

                        Thread.Sleep(TestHelper.DefaultSleepTime * 2);

                        server.GetLogEntry(initialMessage).Validate(initialMessage, LogLevel.Info).Should().BeTrue();
                        server.GetLogEntry(debugMessage).Validate(debugMessage, LogLevel.Debug).Should().BeTrue();
                        server.GetLogEntry(traceMessage).Validate(traceMessage, LogLevel.Trace).Should().BeTrue();
                        server.GetLogEntry(warnMessage).Validate(warnMessage, LogLevel.Warn).Should().BeTrue();
                        server.GetLogEntry(errorMessage).Validate(errorMessage, LogLevel.Error).Should().BeTrue();
                        server.GetLogEntry(fatalMessage).Validate(fatalMessage, LogLevel.Fatal).Should().BeTrue();
                        server.GetLogEntry(finalMessage).Validate(finalMessage, LogLevel.Info).Should().BeTrue();
                    }
            }
        }