public void WriteLine(string message, OutputWindowTarget target = OutputWindowTarget.Npm)
        {
            if (this.lazyOutputWindow == null)
            {
                throw new InvalidOperationException($"Ensure the output window is initialized by calling '{nameof(ShowWindow)}' first.");
            }

            var hr = this.GetOutputPane(target).OutputStringThreadSafe(message + Environment.NewLine);

            Debug.Assert(ErrorHandler.Succeeded(hr));
        }
Exemple #2
0
        public void WriteLine(string message, OutputWindowTarget target = OutputWindowTarget.Npm)
        {
            if (!this.IsInitialized())
            {
                throw new InvalidOperationException("You need to initialize the output panes before using them.");
            }

            var hr = this.lazyOutputPaneCollection[target].OutputStringThreadSafe(message + Environment.NewLine);

            Debug.Assert(ErrorHandler.Succeeded(hr));
        }
        private IVsOutputWindowPane GetOutputPane(OutputWindowTarget target)
        {
            if (this.lazyOutputPaneCollection.TryGetValue(target, out var lazyOutputPane))
            {
                return(lazyOutputPane);
            }
            else
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                var(title, guid) = GetPaneInfo(target);
                var outputWindow = (IVsOutputWindow)this.ServiceProvider.GetService(typeof(SVsOutputWindow));

                // Try to get the workspace pane if it has already been registered
                var hr = outputWindow.GetPane(guid, out lazyOutputPane);

                // If the workspace pane has not been registered before, create it
                if (lazyOutputPane == null || ErrorHandler.Failed(hr))
                {
                    if (ErrorHandler.Failed(outputWindow.CreatePane(guid, title, fInitVisible: 1, fClearWithSolution: 1)) ||
                        ErrorHandler.Failed(outputWindow.GetPane(guid, out lazyOutputPane)))
                    {
                        return(null);
                    }

                    // Must activate the workspace pane for it to show up in the output window
                    lazyOutputPane.Activate();
                }

                this.lazyOutputPaneCollection.Add(target, lazyOutputPane);
                return(lazyOutputPane);
            }

            (string title, Guid guid) GetPaneInfo(OutputWindowTarget pane)
            {
                switch (pane)
                {
                case OutputWindowTarget.Npm:
                    return("Npm", VSPackageManagerPaneGuid);

                case OutputWindowTarget.Tsc:
                    return("Tsc", TscPaneGuid);      /* no need to localize since name of exe */

                default:
                    throw new ArgumentOutOfRangeException(nameof(pane));
                }
            }
        }
        /// <summary>
        /// Initialize the NLog output window target.
        /// </summary>
        private void InitializeLogging()
        {
            using (var options = GetDialogPage(typeof(CSourceFileOptions)) as CSourceFileOptions)
            {
                var config = LogManager.Configuration ?? new LoggingConfiguration();

                var outputWindowTarget = new OutputWindowTarget()
                {
                    PaneName = "C Header Generator",
                    Layout   = options.LogLayout
                };
                config.AddTarget("outputWindow", outputWindowTarget);

                var rule = new LoggingRule("*", NLog.LogLevel.FromString(options.LogLevel.ToString()), outputWindowTarget);
                config.LoggingRules.Add(rule);

                LogManager.Configuration = config;
            }
        }