예제 #1
0
        public void ValidVerbosities()
        {
            string[]          verbositySettings     = new string[] { "Q", "quiet", "m", "minimal", "N", "normal", "d", "detailed", "diag", "DIAGNOSTIC" };
            LoggerVerbosity[] verbosityEnumerations = new LoggerVerbosity[] { LoggerVerbosity.Quiet, LoggerVerbosity.Quiet,
                                                                              LoggerVerbosity.Minimal, LoggerVerbosity.Minimal,
                                                                              LoggerVerbosity.Normal, LoggerVerbosity.Normal,
                                                                              LoggerVerbosity.Detailed, LoggerVerbosity.Detailed,
                                                                              LoggerVerbosity.Diagnostic, LoggerVerbosity.Diagnostic };
            for (int i = 0; i < verbositySettings.Length; i++)
            {
                FileLogger fl = new FileLogger();
                fl.Parameters = "verbosity=" + verbositySettings[i] + ";";
                EventSourceSink es = new EventSourceSink();
                fl.Initialize(es);
                fl.Shutdown();
                Assert.Equal(fl.Verbosity, verbosityEnumerations[i]);
            }

            // Do the same using the v shorthand
            for (int i = 0; i < verbositySettings.Length; i++)
            {
                FileLogger fl = new FileLogger();
                fl.Parameters = "v=" + verbositySettings[i] + ";";
                EventSourceSink es = new EventSourceSink();
                fl.Initialize(es);
                fl.Shutdown();
                Assert.Equal(fl.Verbosity, verbosityEnumerations[i]);
            }
        }
예제 #2
0
        public void SpecificVerbosity()
        {
            string log = null;

            try
            {
                log = GetTempFilename();
                FileLogger      fl = new FileLogger();
                EventSourceSink es = new EventSourceSink();
                fl.Parameters = "verbosity=diagnostic;logfile=" + log; // diagnostic specific setting
                fl.Verbosity  = LoggerVerbosity.Quiet;                 // quiet global setting
                fl.Initialize(es);
                fl.MessageHandler(null, new BuildMessageEventArgs("message here", null, null, MessageImportance.High));
                fl.Shutdown();

                // expect message to appear because diagnostic not quiet verbosity was used
                VerifyFileContent(log, "message here");
            }
            finally
            {
                if (null != log)
                {
                    File.Delete(log);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Creates a FileLogger, sets its parameters and initializes it,
        /// logs a message to it, and calls shutdown
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private void SetUpFileLoggerAndLogMessage(string parameters, BuildMessageEventArgs message)
        {
            FileLogger      fl = new FileLogger();
            EventSourceSink es = new EventSourceSink();

            fl.Parameters = parameters;
            fl.Initialize(es);
            fl.MessageHandler(null, message);
            fl.Shutdown();
            return;
        }
예제 #4
0
 public void InvalidVerbosity()
 {
     Assert.Throws <LoggerException>(() =>
     {
         FileLogger fl      = new FileLogger();
         fl.Parameters      = "verbosity=CookiesAndCream";
         EventSourceSink es = new EventSourceSink();
         fl.Initialize(es);
     }
                                     );
 }
예제 #5
0
        public void InvalidEncoding()
        {
            Assert.Throws <LoggerException>(() =>
            {
                string log = null;

                try
                {
                    log                = GetTempFilename();
                    FileLogger fl      = new FileLogger();
                    EventSourceSink es = new EventSourceSink();
                    fl.Parameters      = "encoding=foo;logfile=" + log;
                    fl.Initialize(es);
                }
                finally
                {
                    if (null != log)
                    {
                        File.Delete(log);
                    }
                }
            }
                                            );
        }