Esempio n. 1
0
 public static void LogExpandChildrenValidationError(NatvisLoggingLevel loggingLevel,
                                                     NatvisDiagnosticLogger logger,
                                                     string visualizerName,
                                                     string typeName, string errorCause)
 {
     LogAndGetExpandChildrenValidationError(loggingLevel, logger, visualizerName, typeName,
                                            errorCause);
 }
Esempio n. 2
0
        public static ErrorVariableInformation LogAndGetExpandChildrenValidationError(
            NatvisLoggingLevel loggingLevel, NatvisDiagnosticLogger logger, string visualizerName,
            string typeName, string errorCause)
        {
            string errMessage = $"(Natvis) Failed to expand {visualizerName} node for type " +
                                $"'{typeName}'. Reason: {errorCause}.";

            logger.Log(loggingLevel, errMessage);
            return(new ErrorVariableInformation("<Error>", errMessage));
        }
        /// <param name="logger">
        ///  The internal NLog logger to use to output messages.
        ///
        ///  This should not be null, if no logging is desired, pass in a null logger, by calling
        ///  <c>NLog.LogFactory.CreateNullLogger()</c>, or set the logging level to
        ///  <c>OFF</c>.
        /// </param>
        /// <param name="level">
        ///  The desired verbosity of logging.
        ///  All levels up to and including the selected logging level are logged.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///  Thrown when <paramref name="logger"/> is <c>null</c>.
        /// </exception>
        public NatvisDiagnosticLogger(ILogger logger, NatvisLoggingLevel level)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            this.logger = logger;
            SetLogLevel(level);
        }
        /// <param name="level">The severity of this message.</param>
        /// <param name="deferredMessage">
        ///  A lambda returning the message string, which will only be called if the message is
        ///  actually going to be logged.
        /// </param>
        /// <exception cref="System.ComponentModel.InvalidEnumArgumentException">
        ///  Thrown if the <paramref name="level"/> is not a valid <c>LoggingLevel</c>.
        /// </exception>
        public void Log(NatvisLoggingLevel level, LogMessageGenerator deferredMessage)
        {
            switch (level)
            {
            case NatvisLoggingLevel.OFF:     return;

            case NatvisLoggingLevel.ERROR:   Error(deferredMessage);   return;

            case NatvisLoggingLevel.WARNING: Warning(deferredMessage); return;

            case NatvisLoggingLevel.VERBOSE: Verbose(deferredMessage); return;

            default: throw new System.ComponentModel.InvalidEnumArgumentException(
                          $"Unhandled logging level [{level}] for message [{deferredMessage()}]");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Writes a log to Trace and this.logger.
        /// </summary>
        void TraceWriteLine(NatvisLoggingLevel level, string message)
        {
            if (_logger.ShouldLog(level))
            {
                _logger.Log(level, message);
            }
            else
            {
                string traceMsg = message;
                if (level == NatvisLoggingLevel.ERROR)
                {
                    traceMsg = "ERROR: " + message;
                }

                Trace.WriteLine(traceMsg);
            }
        }
 /// <summary>
 /// Specify the max log level that should be captured.
 /// </summary>
 /// <param name="level">
 /// The desired verbosity of logging.
 /// All levels up to and including the selected logging level are logged.
 /// </param>
 public void SetLogLevel(NatvisLoggingLevel level)
 {
     this.level = level;
     Trace.WriteLine($"Natvis log level set to {level}.");
 }
 /// <summary>
 /// Returns true if the specified log level should be captured.
 /// </summary>
 public bool ShouldLog(NatvisLoggingLevel level)
 {
     return(this.level >= level);
 }