Esempio n. 1
0
        private static void Main()
        {
            using (var hook = new MyHook())
            {
                // This tells all dlib loggers to send their logging events to the hook object.  That
                // is, any time a logger generates a message it will call hook.log() with the message
                // contents.  Additionally, hook.log() will also only be called from one thread at a
                // time so it is safe to use this kind of hook in a multi-threaded program with many
                // loggers in many threads.
                Dlib.SetAllLoggingOutputHooks(hook);
                // It should also be noted that the hook object must not be destructed while the
                // loggers are still in use.  So it is a good idea to declare the hook object
                // somewhere where it will live the entire lifetime of the program, as we do here.


                using (var dlog = new Logger("main"))
                {
                    // Tell the dlog logger to emit a message for all logging events rather than its
                    // default behavior of only logging LERROR or above.
                    dlog.SetLevel(LogLevel.All);

                    // All these message go to my_log_file.txt, but only the last two go to the console.
                    dlog.WriteLine(LogLevel.Debug, "This is a debugging message.");
                    dlog.WriteLine(LogLevel.Info, "This is an informational message.");
                    dlog.WriteLine(LogLevel.Error, "An error message!");
                }
            }
        }
        public void STE_should_not_run_cancelled_shutdown_hooks()
        {
            var executor = new SingleThreadEventExecutor("Foo" + ThreadLocalRandom.Current.Next(),
                TimeSpan.FromMilliseconds(100));

            var hook = new MyHook();
            executor.AddShutdownHook(hook);
            executor.RemoveShutdownHook(hook);
            executor.GracefulShutdownAsync().Wait();
            Assert.False(hook.WasExecuted);
        }
Esempio n. 3
0
        public void STE_should_not_run_cancelled_shutdown_hooks()
        {
            var executor = new SingleThreadEventExecutor("Foo" + ThreadLocalRandom.Current.Next(),
                                                         TimeSpan.FromMilliseconds(100));

            var hook = new MyHook();

            executor.AddShutdownHook(hook);
            executor.RemoveShutdownHook(hook);
            executor.GracefulShutdownAsync().Wait();
            Assert.False(hook.WasExecuted);
        }
        public void STE_should_run_shutdown_hooks()
        {
            var executor = new SingleThreadEventExecutor("Foo" + ThreadLocalRandom.Current.Next(),
                TimeSpan.FromMilliseconds(100));

            var hook = new MyHook();
            executor.AddShutdownHook(hook);

            // added a sanity check here to make sure that normal scheduled operations can run
            Func<bool> myFunc = () => true;
            var task = executor.SubmitAsync(myFunc);
            Assert.True(task.Wait(200), "Should have completed task in under 200 milliseconds");
            Assert.True(task.Result);
            // end sanity check, begin actual test

            executor.GracefulShutdownAsync().Wait();
            Assert.True(hook.WasExecuted);
        }
Esempio n. 5
0
        public void STE_should_run_shutdown_hooks()
        {
            var executor = new SingleThreadEventExecutor("Foo" + ThreadLocalRandom.Current.Next(),
                                                         TimeSpan.FromMilliseconds(100));

            var hook = new MyHook();

            executor.AddShutdownHook(hook);

            // added a sanity check here to make sure that normal scheduled operations can run
            Func <bool> myFunc = () => true;
            var         task   = executor.SubmitAsync(myFunc);

            Assert.True(task.Wait(200), "Should have completed task in under 200 milliseconds");
            Assert.True(task.Result);
            // end sanity check, begin actual test

            executor.GracefulShutdownAsync().Wait();
            Assert.True(hook.WasExecuted);
        }