public void Initialize(IEventSource eventSource)
        {
            ErrorUtilities.VerifyThrowArgumentNull(eventSource, "eventSource");
            ParseFileLoggerParameters();
            string fileName = logFile;

            try
            {
                // Create a new file logger and pass it some parameters to make the build log very detailed
                nodeFileLogger = new FileLogger();
                string extension = Path.GetExtension(logFile);
                // If there is no extension add a default of .log to it
                if (String.IsNullOrEmpty(extension))
                {
                    logFile  += ".log";
                    extension = ".log";
                }
                // Log 0-based node id's, where 0 is the parent. This is a little unnatural for the reader,
                // but avoids confusion by being consistent with the Engine and any error messages it may produce.
                fileName = logFile.Replace(extension, nodeId + extension);
                nodeFileLogger.Verbosity  = LoggerVerbosity.Detailed;
                nodeFileLogger.Parameters = "ShowEventId;ShowCommandLine;logfile=" + fileName + ";" + parameters;
            }
            catch (ArgumentException e) // Catching Exception, but rethrowing unless it's a well-known exception.
            {
                if (nodeFileLogger != null)
                {
                    nodeFileLogger.Shutdown();
                }

                string errorCode;
                string helpKeyword;
                string message = ResourceUtilities.FormatResourceString(out errorCode, out helpKeyword, "InvalidFileLoggerFile", fileName, e.Message);
                throw new LoggerException(message, e, errorCode, helpKeyword);
            }

            // Say we are operating on 2 processors so we can get the multiproc output
            nodeFileLogger.Initialize(eventSource, 2);
        }
Exemple #2
0
        public void SpecificVerbosity()
        {
            string log = null;

            try
            {
                log = GetTempFilename();
                FileLogger fl = new FileLogger();
                EventSource es = new EventSource();
                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);
            }
        }
Exemple #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();
     EventSource es = new EventSource();
     fl.Parameters = parameters;
     fl.Initialize(es);
     fl.MessageHandler(null, message);
     fl.Shutdown();
     return;
 }
Exemple #4
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] + ";";
                EventSource es = new EventSource();
                fl.Initialize(es);
                fl.Shutdown();
                Assertion.AssertEquals(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] + ";";
                EventSource es = new EventSource();
                fl.Initialize(es);
                fl.Shutdown();
                Assertion.AssertEquals(fl.Verbosity, verbosityEnumerations[i]);
            }
        }
        public void Initialize(IEventSource eventSource)
        {
            ErrorUtilities.VerifyThrowArgumentNull(eventSource, "eventSource");
            ParseFileLoggerParameters();
            string fileName = logFile;
            try
            {
                // Create a new file logger and pass it some parameters to make the build log very detailed
                nodeFileLogger = new FileLogger();
                string extension = Path.GetExtension(logFile);
                // If there is no extension add a default of .log to it
                if (String.IsNullOrEmpty(extension))
                {
                    logFile += ".log";
                    extension = ".log";
                }
                // Log 0-based node id's, where 0 is the parent. This is a little unnatural for the reader,
                // but avoids confusion by being consistent with the Engine and any error messages it may produce.
                fileName = logFile.Replace(extension, nodeId + extension);
                nodeFileLogger.Verbosity = LoggerVerbosity.Detailed;
                nodeFileLogger.Parameters = "ShowEventId;ShowCommandLine;logfile=" + fileName + ";" + parameters;
            }
            catch (ArgumentException e) // Catching Exception, but rethrowing unless it's a well-known exception.
            {

                if(nodeFileLogger != null)
                {
                    nodeFileLogger.Shutdown();
                }

                string errorCode;
                string helpKeyword;
                string message = ResourceUtilities.FormatResourceString(out errorCode, out helpKeyword, "InvalidFileLoggerFile", fileName, e.Message);
                throw new LoggerException(message, e, errorCode, helpKeyword);
            }

            // Say we are operating on 2 processors so we can get the multiproc output
            nodeFileLogger.Initialize(eventSource, 2);
        }