Esempio n. 1
0
 private void LogMessage(
     IRestoreLogMessage logMessage,
     MessageImportance importance,
     LogMessageWithDetails logWithDetails,
     LogMessageAsString logAsString)
 {
     if (logMessage.Code > NuGetLogCode.Undefined)
     {
         // NuGet does not currently have a subcategory while throwing logs, hence string.Empty
         logWithDetails(
             string.Empty,
             Enum.GetName(typeof(NuGetLogCode), logMessage.Code),
             Enum.GetName(typeof(NuGetLogCode), logMessage.Code),
             logMessage.FilePath,
             logMessage.StartLineNumber,
             logMessage.StartColumnNumber,
             logMessage.EndLineNumber,
             logMessage.EndColumnNumber,
             importance,
             logMessage.Message);
     }
     else
     {
         logAsString(importance, logMessage.Message);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Log using with metadata for non mono platforms.
        /// </summary>
        private void LogForNonMono(IRestoreLogMessage message)
        {
            switch (message.Level)
            {
            case LogLevel.Error:
                LogError(message, _taskLogging.LogError, _taskLogging.LogError);
                break;

            case LogLevel.Warning:
                LogError(message, _taskLogging.LogWarning, _taskLogging.LogWarning);
                break;

            case LogLevel.Minimal:
                LogMessage(message, MessageImportance.High, _taskLogging.LogMessage, _taskLogging.LogMessage);
                break;

            case LogLevel.Information:
                LogMessage(message, MessageImportance.Normal, _taskLogging.LogMessage, _taskLogging.LogMessage);
                break;

            case LogLevel.Debug:
            case LogLevel.Verbose:
            default:
                // Default to LogLevel.Debug and low importance
                LogMessage(message, MessageImportance.Low, _taskLogging.LogMessage, _taskLogging.LogMessage);
                break;
            }
        }
        /// <summary>
        /// Method is used to check is a warning should be suppressed due to package specific no warn properties.
        /// </summary>
        /// <param name="message">Message to be checked for no warn.</param>
        /// <returns>bool indicating if the IRestoreLogMessage should be suppressed or not.</returns>
        private bool ApplyPackageSpecificNoWarnProperties(IRestoreLogMessage message)
        {
            if (message.Level == LogLevel.Warning &&
                PackageSpecificWarningProperties != null &&
                !string.IsNullOrEmpty(message.LibraryId))
            {
                // If the message does not contain a target graph, assume that it is applicable for all project frameworks.
                if (!message.TargetGraphs.Select(GetNuGetFramework).Any())
                {
                    // Suppress the warning if the code + libraryId combination is suppressed for all project frameworks.
                    if (ProjectFrameworks.Count > 0 &&
                        ProjectFrameworks.All(e => PackageSpecificWarningProperties.Contains(message.Code, message.LibraryId, e)))
                    {
                        return(true);
                    }
                }
                else
                {
                    // Get all the target graphs for which code + libraryId combination is not suppressed.
                    message.TargetGraphs = message
                                           .TargetGraphs
                                           .Where(e => !PackageSpecificWarningProperties.Contains(message.Code, message.LibraryId, GetNuGetFramework(e)))
                                           .ToList();

                    // If the message is left with no target graphs then suppress it.
                    if (message.TargetGraphs.Count == 0)
                    {
                        return(true);
                    }
                }
            }

            // The message is not a warning or it does not contain a LibraryId or it is not suppressed in package specific settings.
            return(false);
        }
Esempio n. 4
0
 /// <summary>
 /// Decides if the log should be passed to the inner logger.
 /// </summary>
 /// <param name="message">IRestoreLogMessage to be logged.</param>
 /// <returns>bool indicating if this message should be logged.</returns>
 protected bool DisplayMessage(IRestoreLogMessage message)
 {
     if (message.Level == LogLevel.Error || message.Level == LogLevel.Warning)
     {
         return((!_hideWarningsAndErrors || message.ShouldDisplay) && message.Level >= VerbosityLevel);
     }
     else
     {
         return(message.Level >= VerbosityLevel);
     }
 }
 /// <summary>
 /// Attempts to suppress a warning log message or upgrade it to error log message.
 /// The decision is made based on the Package Specific or Project wide warning properties.
 /// </summary>
 /// <param name="message">Message that should be suppressed or upgraded to an error.</param>
 /// <returns>Bool indicating is the warning should be suppressed or not.
 /// If not then the param message sould have been mutated to an error</returns>
 public bool ApplyWarningProperties(IRestoreLogMessage message)
 {
     if (ApplyProjectWideNoWarnProperties(message) || ApplyPackageSpecificNoWarnProperties(message))
     {
         return(true);
     }
     else
     {
         ApplyWarningAsErrorProperties(message);
         return(false);
     }
 }
 public static IAssetsLogMessage Create(IRestoreLogMessage logMessage)
 {
     return(new AssetsLogMessage(logMessage.Level, logMessage.Code, logMessage.Message)
     {
         ProjectPath = logMessage.ProjectPath,
         WarningLevel = logMessage.WarningLevel,
         FilePath = logMessage.FilePath,
         LibraryId = logMessage.LibraryId,
         TargetGraphs = logMessage.TargetGraphs,
         StartLineNumber = logMessage.StartLineNumber,
         StartColumnNumber = logMessage.StartColumnNumber,
         EndLineNumber = logMessage.EndLineNumber,
         EndColumnNumber = logMessage.EndColumnNumber
     });
 }
Esempio n. 7
0
        public void Log(IRestoreLogMessage message)
        {
            // This will be true only when the Message is a Warning and should be suppressed.
            if (WarningPropertiesCollection == null || !WarningPropertiesCollection.ApplyWarningProperties(message))
            {
                if (CollectMessage(message.Level))
                {
                    _errors.Enqueue(message);
                }

                if (DisplayMessage(message))
                {
                    _innerLogger.Log(message);
                }
            }
        }
Esempio n. 8
0
        public Task LogAsync(IRestoreLogMessage message)
        {
            // This will be true only when the Message is a Warning and should be suppressed.
            if (WarningPropertiesCollection == null || !WarningPropertiesCollection.ApplyWarningProperties(message))
            {
                if (CollectMessage(message.Level))
                {
                    _errors.Enqueue(message);
                }

                if (DisplayMessage(message))
                {
                    return(_innerLogger.LogAsync(message));
                }
            }

            return(Task.FromResult(0));
        }
        /// <summary>
        /// Attempts to suppress a warning log message or upgrade it to error log message.
        /// The decision is made based on the Package Specific or Project wide warning properties.
        /// </summary>
        /// <param name="message">Message that should be suppressed or upgraded to an error.</param>
        /// <returns>Bool indicating is the warning should be suppressed or not.
        /// If not then the param message sould have been mutated to an error</returns>
        public bool ApplyWarningProperties(IRestoreLogMessage message)
        {
            if (message.Level != LogLevel.Warning)
            {
                return(false);
            }
            else
            {
                if (!string.IsNullOrEmpty(message.LibraryId) && PackageSpecificWarningProperties != null)
                {
                    // The message contains a LibraryId
                    // First look at PackageSpecificWarningProperties and then at ProjectWideWarningProperties
                    if (message.TargetGraphs.Count == 0)
                    {
                        if (PackageSpecificWarningProperties.Contains(message.Code, message.LibraryId))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        var newTargetGraphList = new List <string>();
                        foreach (var targetGraph in message.TargetGraphs)
                        {
                            if (!PackageSpecificWarningProperties.Contains(message.Code, message.LibraryId, GetNuGetFramework(targetGraph)))
                            {
                                newTargetGraphList.Add(targetGraph);
                            }
                        }

                        message.TargetGraphs = newTargetGraphList;

                        if (message.TargetGraphs.Count == 0)
                        {
                            return(true);
                        }
                    }
                }

                // The message does not contain a LibraryId or it is not suppressed in package specific settings
                // Use ProjectWideWarningProperties
                return(ProjectWideWarningProperties != null && ApplyProjectWideWarningProperties(message));
            }
        }
Esempio n. 10
0
 public RestoreCommandException(IRestoreLogMessage logMessage)
     : base(logMessage?.Message)
 {
     _logMessage = logMessage ?? throw new ArgumentNullException(nameof(logMessage));
 }
 /// <summary>
 /// Method is used to upgrade a warning to an error if needed.
 /// </summary>
 /// <param name="message">Message which should be upgraded to error if needed.</param>
 public void ApplyWarningAsErrorProperties(IRestoreLogMessage message)
 {
     ApplyProjectWideWarningsAsErrorProperties(message);
 }
 /// <summary>
 /// Attempts to suppress a warning log message.
 /// The decision is made based on the Package Specific or Project wide no warn properties.
 /// </summary>
 /// <param name="message">Message that should be suppressed.</param>
 /// <returns>Bool indicating is the warning should be suppressed or not.</returns>
 public bool ApplyNoWarnProperties(IRestoreLogMessage message)
 {
     return(ApplyProjectWideNoWarnProperties(message) || ApplyPackageSpecificNoWarnProperties(message));
 }