Ejemplo n.º 1
0
        /// <summary>
        /// Add console logger in runsettings if exists.
        /// </summary>
        /// <param name="document">Runsettings document.</param>
        /// <param name="loggerRunSettings">Logger run settings.</param>
        /// <returns>True if updated console logger in runsettings successfully.</returns>
        private bool UpdateConsoleLoggerIfExists(
            XmlDocument document,
            LoggerRunSettings loggerRunSettings)
        {
            var defaultConsoleLogger = new LoggerSettings
            {
                FriendlyName = ConsoleLogger.FriendlyName,
                Uri          = new Uri(ConsoleLogger.ExtensionUri)
            };

            var existingLoggerIndex = loggerRunSettings.GetExistingLoggerIndex(defaultConsoleLogger);

            // Update assemblyQualifiedName and codeBase of existing logger.
            if (existingLoggerIndex >= 0)
            {
                var consoleLogger = loggerRunSettings.LoggerSettingsList[existingLoggerIndex];
                consoleLogger.AssemblyQualifiedName = typeof(ConsoleLogger).AssemblyQualifiedName;
                consoleLogger.CodeBase = typeof(ConsoleLogger).GetTypeInfo().Assembly.Location;
                RunSettingsProviderExtensions.UpdateRunSettingsXmlDocumentInnerXml(
                    document,
                    Constants.LoggerRunSettingsName,
                    loggerRunSettings.ToXml().InnerXml);

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add console logger in runsettings.
        /// </summary>
        /// <param name="document">Runsettings document.</param>
        /// <param name="loggerRunSettings">Logger run settings.</param>
        private void AddConsoleLogger(XmlDocument document, LoggerRunSettings loggerRunSettings)
        {
            var consoleLogger = new LoggerSettings
            {
                FriendlyName          = ConsoleLogger.FriendlyName,
                Uri                   = new Uri(ConsoleLogger.ExtensionUri),
                AssemblyQualifiedName = typeof(ConsoleLogger).AssemblyQualifiedName,
                CodeBase              = typeof(ConsoleLogger).GetTypeInfo().Assembly.Location,
                IsEnabled             = true
            };

            loggerRunSettings.LoggerSettingsList.Add(consoleLogger);
            RunSettingsProviderExtensions.UpdateRunSettingsXmlDocumentInnerXml(
                document,
                Constants.LoggerRunSettingsName,
                loggerRunSettings.ToXml().InnerXml);
        }