public void MessageRaised(object sender, BuildMessageEventArgs args)
        {
            try
            {
                lock (syncLock)
                {
                    if (args is TargetSkippedEventArgs2 targetSkipped)
                    {
                        TargetSkipped(targetSkipped);
                        return;
                    }

                    if (!sawCulture &&
                        args.SenderName == "BinaryLogger" &&
                        args.Message is string message &&
                        message.StartsWith("CurrentUICulture", StringComparison.Ordinal))
                    {
                        sawCulture = true;
                        var    kvp     = TextUtilities.ParseNameValue(message);
                        string culture = kvp.Value;
                        if (!string.IsNullOrEmpty(culture))
                        {
                            Strings.Initialize(culture);
                        }
                    }

                    messageProcessor.Process(args);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
示例#2
0
        /// <summary>
        /// Initializes the logger and subscribes to the relevant events.
        /// </summary>
        /// <param name="eventSource">The available events that processEvent logger can subscribe to.</param>
        public override void Initialize(IEventSource eventSource)
        {
            Environment.SetEnvironmentVariable("MSBUILDTARGETOUTPUTLOGGING", "true");
            Environment.SetEnvironmentVariable("MSBUILDLOGIMPORTS", "1");

            // Set this environment variable to log AssemblyFoldersEx search results from ResolveAssemblyReference
            // Environment.SetEnvironmentVariable("MSBUILDLOGVERBOSERARSEARCHRESULTS", "true");

            ProcessParameters();

            if (SaveLogToDisk)
            {
                try
                {
                    projectImportsCollector = new ProjectImportsCollector(_logFile);
                }
                catch (Exception ex)
                {
                    throw new LoggerException($"Failed to create the source archive for log file {_logFile}", ex);
                }
            }

            construction = new Construction();

            Strings.Initialize();

            eventSource.BuildStarted      += construction.BuildStarted;
            eventSource.BuildFinished     += construction.BuildFinished;
            eventSource.ProjectStarted    += construction.ProjectStarted;
            eventSource.ProjectFinished   += construction.ProjectFinished;
            eventSource.TargetStarted     += construction.TargetStarted;
            eventSource.TargetFinished    += construction.TargetFinished;
            eventSource.TaskStarted       += construction.TaskStarted;
            eventSource.TaskFinished      += construction.TaskFinished;
            eventSource.MessageRaised     += construction.MessageRaised;
            eventSource.WarningRaised     += construction.WarningRaised;
            eventSource.ErrorRaised       += construction.ErrorRaised;
            eventSource.CustomEventRaised += construction.CustomEventRaised;
            eventSource.StatusEventRaised += construction.StatusEventRaised;

            if (projectImportsCollector != null)
            {
                eventSource.AnyEventRaised += EventSource_AnyEventRaised;
            }
        }
示例#3
0
        public void MessageRaised(object sender, BuildMessageEventArgs args)
        {
            try
            {
                lock (syncLock)
                {
                    if (args is TargetSkippedEventArgs targetSkipped)
                    {
                        TargetSkipped(targetSkipped);
                        return;
                    }

                    if (!sawCulture && args.SenderName == "BinaryLogger" && args.Message.StartsWith("CurrentUICulture"))
                    {
                        sawCulture = true;
                        int equalsIndex = args.Message.IndexOf("=");
                        if (equalsIndex > 0 && equalsIndex < args.Message.Length - 1)
                        {
                            string culture = args.Message.Substring(equalsIndex + 1, args.Message.Length - 1 - equalsIndex);

                            // read language from log and initialize resource strings
                            if (!String.IsNullOrEmpty(culture))
                            {
                                Strings.Initialize(culture, force: true);
                            }
                        }
                    }

                    messageProcessor.Process(args);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }