예제 #1
0
        public ILogger CreateLogger(LoggerVerbosity defaultVerbosity)
        {
            string assemblyName = null;
            string assemblyFile = null;

            if (File.Exists(Assembly))
            {
                assemblyFile = Assembly;
            }
            else
            {
                assemblyName = Assembly;
            }

            var loggerDescription = new Microsoft.Build.Logging.LoggerDescription(
                ClassName,
                assemblyName,
                assemblyFile,
                Parameters,
                Verbosity ?? defaultVerbosity);

            var logger = loggerDescription.CreateLogger();

            logger.Verbosity = Verbosity ?? defaultVerbosity;
            if (loggerDescription.LoggerSwitchParameters != null)
            {
                logger.Parameters = loggerDescription.LoggerSwitchParameters;
            }

            return(logger);
        }
예제 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="nodeId">The node id.</param>
 /// <param name="buildParameters">The build parameters</param>
 /// <param name="forwardingLoggers">The forwarding loggers.</param>
 /// <param name="appDomainSetup">The AppDomain setup information.</param>
 public NodeConfiguration
     (
     int nodeId,
     BuildParameters buildParameters,
     LoggerDescription[] forwardingLoggers,
     AppDomainSetup appDomainSetup
     )
 {
     _nodeId = nodeId;
     _buildParameters = buildParameters;
     _forwardingLoggers = forwardingLoggers;
     _appDomainSetup = appDomainSetup;
 }
예제 #3
0
파일: XMake.cs 프로젝트: assafnativ/msbuild
        /// <summary>
        /// Loads a logger from its assembly, instantiates it, and handles errors.
        /// </summary>
        /// <returns>Instantiated logger.</returns>
        private static ILogger CreateAndConfigureLogger
        (
            LoggerDescription loggerDescription,
            LoggerVerbosity verbosity,
            string unquotedParameter
        )
        {
            ILogger logger = null;

            try
            {
                logger = loggerDescription.CreateLogger();

                if (logger == null)
                {
                    InitializationException.VerifyThrow(logger != null, "LoggerNotFoundError", unquotedParameter);
                }
            }
            catch (IOException e)
            {
                InitializationException.Throw("LoggerCreationError", unquotedParameter, e, false);
            }
            catch (BadImageFormatException e)
            {
                InitializationException.Throw("LoggerCreationError", unquotedParameter, e, false);
            }
            catch (SecurityException e)
            {
                InitializationException.Throw("LoggerCreationError", unquotedParameter, e, false);
            }
            catch (ReflectionTypeLoadException e)
            {
                InitializationException.Throw("LoggerCreationError", unquotedParameter, e, false);
            }
            catch (MemberAccessException e)
            {
                InitializationException.Throw("LoggerCreationError", unquotedParameter, e, false);
            }
            catch (TargetInvocationException e)
            {
                InitializationException.Throw("LoggerFatalError", unquotedParameter, e.InnerException, true);
            }

            // Configure the logger by setting the verbosity level and parameters
            try
            {
                // set its verbosity level
                logger.Verbosity = verbosity;

                // set the logger parameters (if any)
                if (loggerDescription.LoggerSwitchParameters != null)
                {
                    logger.Parameters = loggerDescription.LoggerSwitchParameters;
                }
            }

            catch (LoggerException)
            {
                // Logger failed politely during parameter/verbosity setting
                throw;
            }
            catch (Exception e)
            {
                InitializationException.Throw("LoggerFatalError", unquotedParameter, e, true);
            }

            return logger;
        }
예제 #4
0
파일: XMake.cs 프로젝트: assafnativ/msbuild
        /// <summary>
        /// Process the file logger switches and attach the correct file loggers. Internal for testing
        /// </summary>
        internal static void ProcessDistributedFileLogger
        (
            bool distributedFileLogger,
            string[] fileLoggerParameters,
            List<DistributedLoggerRecord> distributedLoggerRecords,
            ArrayList loggers,
            int cpuCount
        )
        {
            if (distributedFileLogger)
            {
                string fileParameters = string.Empty;
                if ((fileLoggerParameters != null) && (fileLoggerParameters.Length > 0))
                {
                    // Join the file logger parameters into one string seperated by semicolons
                    fileParameters = AggregateParameters(null, fileLoggerParameters);
                }

                // Check to see if the logfile parameter has been set, if not set it to the current directory
                string logFileParameter = ExtractAnyLoggerParameter(fileParameters, "logfile");

                string logFileName = ExtractAnyParameterValue(logFileParameter);

                try
                {
                    // If the path is not an absolute path set the path to the current directory of the exe combined with the relative path
                    // If the string is empty then send it through as the distributed file logger WILL deal with EMPTY logfile paths
                    if (!String.IsNullOrEmpty(logFileName) && !Path.IsPathRooted(logFileName))
                    {
                        fileParameters = fileParameters.Replace(logFileParameter, "logFile=" + Path.Combine(Directory.GetCurrentDirectory(), logFileName));
                    }
                }
                catch (Exception e)
                {
                    if (ExceptionHandling.NotExpectedException(e))
                    {
                        throw;
                    }

                    throw new LoggerException(e.Message, e);
                }

                if (String.IsNullOrEmpty(logFileName))
                {
                    // If the string is not empty and it does not end in a ;, we need to add a ; to seperate what is in the parameter from the logfile
                    // if the string is empty, no ; is needed because logfile is the only parameter which will be passed in
                    if (!String.IsNullOrEmpty(fileParameters) && !fileParameters.EndsWith(";", StringComparison.OrdinalIgnoreCase))
                    {
                        fileParameters += ";";
                    }

                    fileParameters += "logFile=" + Path.Combine(Directory.GetCurrentDirectory(), msbuildLogFileName);
                }

                //Gets the currently loaded assembly in which the specified class is defined
                Assembly engineAssembly = Assembly.GetAssembly(typeof(ProjectCollection));
                string loggerClassName = "Microsoft.Build.Logging.DistributedFileLogger";
                string loggerAssemblyName = engineAssembly.GetName().FullName;
                // Node the verbosity parameter is not used by the Distributed file logger so changing it here has no effect. It must be changed in the distributed file logger
                LoggerDescription forwardingLoggerDescription = new LoggerDescription(loggerClassName, loggerAssemblyName, null, fileParameters, LoggerVerbosity.Detailed);
                // Use the null as the central Logger, this will cause the engine to instantiate the NullCentralLogger, this logger will throw an exception if anything except for the buildstarted and buildFinished events are sent
                DistributedLoggerRecord distributedLoggerRecord = new DistributedLoggerRecord(null, forwardingLoggerDescription);
                distributedLoggerRecords.Add(distributedLoggerRecord);
            }
        }
예제 #5
0
파일: XMake.cs 프로젝트: assafnativ/msbuild
        /// <summary>
        /// Returns a DistributedLoggerRecord containing this logger and a ConfigurableForwardingLogger. 
        /// Looks at the logger's parameters for any verbosity parameter in order to make sure it is setting up the ConfigurableForwardingLogger
        /// with the verbosity level that the logger will actually use.
        /// </summary>
        private static DistributedLoggerRecord CreateForwardingLoggerRecord(ILogger logger, string loggerParameters, LoggerVerbosity defaultVerbosity)
        {
            string verbosityParameter = ExtractAnyLoggerParameter(loggerParameters, "verbosity", "v");

            string verbosityValue = ExtractAnyParameterValue(verbosityParameter);

            LoggerVerbosity effectiveVerbosity = defaultVerbosity;
            if (!String.IsNullOrEmpty(verbosityValue))
            {
                effectiveVerbosity = ProcessVerbositySwitch(verbosityValue);
            }

            //Gets the currently loaded assembly in which the specified class is defined
            Assembly engineAssembly = Assembly.GetAssembly(typeof(ProjectCollection));
            string loggerClassName = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
            string loggerAssemblyName = engineAssembly.GetName().FullName;
            LoggerDescription forwardingLoggerDescription = new LoggerDescription(loggerClassName, loggerAssemblyName, null, loggerParameters, effectiveVerbosity);
            DistributedLoggerRecord distributedLoggerRecord = new DistributedLoggerRecord(logger, forwardingLoggerDescription);

            return distributedLoggerRecord;
        }
예제 #6
0
 /// <summary>
 /// Registers a distributed logger.
 /// </summary>
 /// <param name="centralLogger">The central logger, which resides on the build manager.</param>
 /// <param name="forwardingLogger">The forwarding logger, which resides on the node.</param>
 /// <returns>True if successful.</returns>
 public bool RegisterDistributedLogger(ILogger centralLogger, LoggerDescription forwardingLogger)
 {
     throw new NotImplementedException();
 }
예제 #7
0
        /// <summary>
        /// Register a distributed logger. This involves creating a new eventsource sink 
        /// and associating this with the central logger. In addition the sinkId needs 
        /// to be put in the loggerDescription so that nodes know what they need to 
        /// tag onto the event so that the message goes to the correct logger.
        /// 
        /// The central logger is initialized before the distributed logger
        /// </summary>
        /// <param name="centralLogger">Central logger to receive messages from the forwarding logger, This logger cannot have been registered before</param>
        /// <param name="forwardingLogger">Logger description which describes how to create the forwarding logger, the logger description cannot have been used before</param>
        /// <returns value="bool">True if the distributed and central logger were registered, false if they either were already registered</returns>
        /// <exception cref="InternalErrorException">If forwardingLogger is null</exception>
        /// <exception cref="LoggerException">If a logger exception is thrown while creating or initializing the distributed or central logger</exception>
        /// <exception cref="InternalLoggerException">If any exception (other than a loggerException)is thrown while creating or initializing the distributed or central logger, we will wrap these exceptions in an InternalLoggerException</exception>
        public bool RegisterDistributedLogger(ILogger centralLogger, LoggerDescription forwardingLogger)
        {
            lock (_lockObject)
            {
                ErrorUtilities.VerifyThrow(_serviceState != LoggingServiceState.Shutdown, " The object is shutdown, should not do any operations on a shutdown component");
                ErrorUtilities.VerifyThrow(forwardingLogger != null, "forwardingLogger was null");
                if (centralLogger == null)
                {
                    centralLogger = new NullCentralLogger();
                }

                IForwardingLogger localForwardingLogger = null;

                // create an eventSourceSink which the central logger will register with to receive the events from the forwarding logger
                EventSourceSink eventSourceSink = new EventSourceSink();

                // If the logger is already in the list it should not be registered again.
                if (_iloggerList.Contains(centralLogger))
                {
                    return false;
                }

                // Assign a unique logger Id to this distributed logger
                int sinkId = _nextSinkId++;
                forwardingLogger.LoggerId = sinkId;
                eventSourceSink.Name = "Sink for forwarding logger \"" + sinkId + "\".";

                // Initialize and register the central logger
                InitializeLogger(centralLogger, eventSourceSink);

                localForwardingLogger = forwardingLogger.CreateForwardingLogger();
                EventRedirectorToSink newRedirector = new EventRedirectorToSink(sinkId, eventSourceSink);
                localForwardingLogger.BuildEventRedirector = newRedirector;
                localForwardingLogger.Parameters = forwardingLogger.LoggerSwitchParameters;
                localForwardingLogger.Verbosity = forwardingLogger.Verbosity;

                // Give the forwarding logger registered on the inproc node the correct ID.
                localForwardingLogger.NodeId = 1;

                // Convert the path to the logger DLL to full path before passing it to the node provider
                forwardingLogger.ConvertPathsToFullPaths();

                CreateFilterEventSource();

                // Initialize and register the forwarding logger
                InitializeLogger(localForwardingLogger, _filterEventSource);

                _loggerDescriptions.Add(forwardingLogger);

                _eventSinkDictionary.Add(sinkId, eventSourceSink);

                return true;
            }
        }
예제 #8
0
        /// <summary>
        /// Register an instantiated logger which implements the ILogger interface. This logger will be registered to a specific event
        /// source (the central logger event source) which will receive all logging messages for a given build.
        /// This should not be used on a node, Loggers are not to be registered on a child node.
        /// </summary>
        /// <param name="logger">ILogger</param>
        /// <returns>True if the logger has been registered successfully. False if the logger was not registered due to it already being registered before</returns>
        /// <exception cref="InternalErrorException">If logger is null</exception>
        public bool RegisterLogger(ILogger logger)
        {
            lock (_lockObject)
            {
                ErrorUtilities.VerifyThrow(_serviceState != LoggingServiceState.Shutdown, " The object is shutdown, should not do any operations on a shutdown component");
                ErrorUtilities.VerifyThrow(logger != null, "logger was null");

                // If the logger is already in the list it should not be registered again.
                if (_iloggerList.Contains(logger))
                {
                    return false;
                }

                // If we have not created a distributed logger to forward all events to the central loggers and
                // a sink which will consume the events and send them to each of the central loggers, we
                // should do that now
                if (_centralLoggerSinkId == -1)
                {
                    // Create a forwarding logger which forwards all events to an eventSourceSink
                    Assembly engineAssembly = Assembly.GetAssembly(typeof(LoggingService));
                    string loggerClassName = "Microsoft.Build.BackEnd.Logging.CentralForwardingLogger";
                    string loggerAssemblyName = engineAssembly.GetName().FullName;
                    LoggerDescription centralLoggerDescrption = new LoggerDescription
                                                                                     (
                                                                                      loggerClassName,
                                                                                      loggerAssemblyName,
                                                                                      null /*Not needed as we are loading from current assembly*/,
                                                                                      string.Empty /*No parameters needed as we are forwarding all events*/,
                                                                                      LoggerVerbosity.Diagnostic /*Not used, but the spirit of the logger is to forward everything so this is the most appropriate verbosity */
                                                                                     );

                    // Registering a distributed logger will initialize the logger, and create and initialize the forwarding logger.
                    // In addition it will register the logging description so that it can be instantiated on a node.
                    RegisterDistributedLogger(logger, centralLoggerDescrption);

                    // Get the Id of the eventSourceSink which was created for the first logger.
                    // We keep a reference to this Id so that all other central loggers registered on this logging service (from registerLogger)
                    // will be attached to that eventSource sink so that they get all of the events forwarded by 
                    // forwarded by the CentralForwardingLogger
                    _centralLoggerSinkId = centralLoggerDescrption.LoggerId;
                }
                else
                {
                    // We have already create a forwarding logger and have a single eventSink which 
                    // a logger can listen to inorder to get all events in the system
                    EventSourceSink eventSource = (EventSourceSink)_eventSinkDictionary[_centralLoggerSinkId];

                    // Initialize and register the logger
                    InitializeLogger(logger, eventSource);
                }

                // Logger has been registered successfully
                return true;
            }
        }
예제 #9
0
 /// <summary>
 /// Registers a distributed logger.
 /// </summary>
 /// <param name="centralLogger">The central logger, which resides on the build manager.</param>
 /// <param name="forwardingLogger">The forwarding logger, which resides on the node.</param>
 /// <returns>True if successful.</returns>
 public bool RegisterDistributedLogger(ILogger centralLogger, LoggerDescription forwardingLogger)
 {
     throw new NotImplementedException();
 }