Пример #1
0
        private void StartLogging()
        {
            _logger = new HostLogger(LogLevel);

            // We need to not write log messages to Stdio
            // if it's being used as a protocol transport
            if (!Stdio)
            {
                var hostLogger = new PSHostLogger(Host.UI);
                _loggerUnsubscribers.Add(_logger.Subscribe(hostLogger));
            }

            string logDirPath = GetLogDirPath();
            string logPath    = Path.Combine(logDirPath, "StartEditorServices.log");

            // Temp debugging sessions may try to reuse this same path,
            // so we ensure they have a unique path
            if (File.Exists(logPath))
            {
                int randomInt = new Random().Next();
                logPath = Path.Combine(logDirPath, $"StartEditorServices-temp{randomInt.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}.log");
            }

            var fileLogger = StreamLogger.CreateWithNewFile(logPath);

            _disposableResources.Add(fileLogger);
            IDisposable fileLoggerUnsubscriber = _logger.Subscribe(fileLogger);

            fileLogger.AddUnsubscriber(fileLoggerUnsubscriber);
            _loggerUnsubscribers.Add(fileLoggerUnsubscriber);

            _logger.Log(PsesLogLevel.Diagnostic, "Logging started");
        }
        private void StartLogging()
        {
            _logger = new HostLogger(LogLevel);

            // We need to not write log messages to Stdio
            // if it's being used as a protocol transport
            if (!Stdio)
            {
                var hostLogger = new PSHostLogger(Host.UI);
                _loggerUnsubscribers.Add(_logger.Subscribe(hostLogger));
            }

            string logPath    = Path.Combine(GetLogDirPath(), "StartEditorServices.log");
            var    fileLogger = StreamLogger.CreateWithNewFile(logPath);

            _disposableResources.Add(fileLogger);
            IDisposable fileLoggerUnsubscriber = _logger.Subscribe(fileLogger);

            fileLogger.AddUnsubscriber(fileLoggerUnsubscriber);
            _loggerUnsubscribers.Add(fileLoggerUnsubscriber);

            _logger.Log(PsesLogLevel.Diagnostic, "Logging started");
        }