示例#1
1
        public override void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity) {
            if (severity == Severity.Warning && !ReportWarning(_context.Verbose, errorCode)) {
                return;
            }

            CountError(severity);

            string path;
            string codeLine;
            int line = span.Start.Line;
            if (sourceUnit != null) {
                path = sourceUnit.Path;
                codeLine = (line > 0) ? sourceUnit.GetCodeLine(line) : null;
            } else {
                path = null;
                codeLine = null;
            }

            if (severity == Severity.Error || severity == Severity.FatalError) {
                throw new SyntaxError(message, path, line, span.Start.Column, codeLine);
            } else {

                if (_WriteSite == null) {
                    Interlocked.CompareExchange(
                        ref _WriteSite,
                        CallSite<Func<CallSite, object, object, object>>.Create(RubyCallAction.Make(_context, "write", 1)),
                        null
                    );
                }

                message = RubyContext.FormatErrorMessage(message, "warning", path, line, span.Start.Column, null);

                _WriteSite.Target(_WriteSite, _context.StandardErrorOutput, MutableString.CreateMutable(message));
            }
        }
		// Token: 0x0600175E RID: 5982
		// RVA: 0x0007310C File Offset: 0x0007130C
		public AiReportTwoObjects(HitObjectBase h1, HitObjectBase h2, BeenCorrectedDelegate corrected, Severity severity, string information, int weblink) : base((h1.EndTime - h2.StartTime) / 2 + h2.StartTime, severity, information, weblink, corrected)
		{
			this.h1 = h1;
			this.h2 = h2;
			this.RelatedHitObjects.Add(h1);
			this.RelatedHitObjects.Add(h2);
		}
示例#3
0
 public OutputMessage(string message, enum_MESSAGETYPE messageType, Severity severity, uint errorCode = 0)
 {
     this.Message = message;
     this.MessageType = messageType;
     this.SeverityValue = severity;
     this.ErrorCode = errorCode;
 }
示例#4
0
 public override void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity) {
     if (severity == Severity.Warning) {
         PythonOps.SyntaxWarning(message, sourceUnit, span, errorCode);
     } else {
         throw PythonOps.SyntaxError(message, sourceUnit, span, errorCode);
     }
 }
		public void CalculatesPriorityValueCorrectly(Facility facility, Severity severity, int expectedPriorityValue)
		{
			var msg = CreateMinimalSyslogMessage(facility, severity);

			string serializedMsg = sut.Serialize(msg);
			Assert.Equal(String.Format("<{0}>1 - - - - -", expectedPriorityValue), serializedMsg);
		}
示例#6
0
 public LoggerMessage(Severity severity, int threadId, string threadName, string message)
 {
     Severity = severity;
     ThreadId = threadId;
     ThreadName = threadName;
     Message = message;
 }
示例#7
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="AreNotEqual" /> class.
 /// </summary>
 /// <param name="name"> The name. </param>
 /// <param name="message"> The message. </param>
 /// <param name="target"> The target. </param>
 /// <param name="comparisonTarget"> The comparison target. </param>
 /// <param name="severity"> The severity. </param>
 public AreNotEqual(string name, string message, object target, object comparisonTarget, Severity severity)
     : base(name, message)
 {
     this.target = target;
     this.comparisonTarget = comparisonTarget;
     Severity = severity;
 }
示例#8
0
		public FormatError(byte[] buffer, int ptr, Severity sev, string msg)
		{
			_buf = buffer;
			_offset = ptr;
			_severity = sev;
			_message = msg;
		}
示例#9
0
 public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity) {
     _source = source;
     _message = message;
     _span = span;
     _errorCode = errorCode;
     //  _severity = severity;
 }
		public void TrackTrace(string message, Severity severity, IDictionary<string, string> properties)
		{
			LogEventLevel level = LogEventLevel.Verbose;
			switch (severity)
			{
				case Severity.Off:
					return;
				case Severity.Error:
					level = LogEventLevel.Error;
					break;
				case Severity.Warning:
					level = LogEventLevel.Warning;
					break;
				case Severity.Verbose:
				case Severity.Verbose2:
				case Severity.Verbose3:
					level = LogEventLevel.Verbose;
					break;
			}

			if (_client.IsEnabled(level))
			{
				var logProperties = new List<LogEventProperty>();
				if (properties != null)
					logProperties.AddRange(properties.Select(x => new LogEventProperty(x.Key, new ScalarValue(x.Value))));

				_client.Write(new LogEvent(DateTimeOffset.UtcNow, level, null,
					new MessageTemplate("{message}", new []{new TextToken(message)}), logProperties));
			}
		}
示例#11
0
 public override void Add(string message, NewLineLocation[] lineLocations, int startIndex, int endIndex, int errorCode, Severity severity) {
     if (severity == Severity.Error || severity == Severity.FatalError) {
         _errors.Add(new ErrorResult(message, new SourceSpan(NewLineLocation.IndexToLocation(lineLocations, startIndex), NewLineLocation.IndexToLocation(lineLocations, endIndex))));
     } else if (severity == Severity.Warning) {
         _warnings.Add(new ErrorResult(message, new SourceSpan(NewLineLocation.IndexToLocation(lineLocations, startIndex), NewLineLocation.IndexToLocation(lineLocations, endIndex))));
     }
 }
示例#12
0
文件: Logger.cs 项目: DevJonny/Russ
        private static void PreProcess(Severity severity, string additionalMessage, Exception exception)
        {
            var callStack = new StackTrace(1, true);
            var stackFrame = callStack.GetFrame(1);
            var log = new Log
            {
                MethodName = stackFrame.GetMethod().Name,
                ClassName = stackFrame.GetMethod().DeclaringType.Name,
                ApplicationName = stackFrame.GetMethod().DeclaringType.Assembly.GetName().Name,
                LineNumber = stackFrame.GetFileLineNumber(),
                Severity = (int)severity,
                Message = $"Message: {additionalMessage ?? ""}"
            };

            if (exception.IsNotNull())
            {
                log.Message += $" Exception: {(exception.IsNotNull() ? exception.ToString() : "")}";
            }

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Logs.Add(log);
                ctx.SaveChanges();
            }
        }
示例#13
0
	    public FormatError(byte[] buffer, int ptr, Severity sev, String msg)
        {
		    buf = buffer;
		    offset = ptr;
		    severity = sev;
		    message = msg;
	    }
示例#14
0
 private static void Log(Severity severity, string message)
 {
     if (_logAction != null)
         _logAction(severity, message);
     else
         Console.WriteLine($"{severity}: {message}");
 }
示例#15
0
 public LogEntry(string message, Type sourceOfLogMessage, DateTime timestamp, Severity severity)
 {
     Message = message;
     SourceOfLogMessage = sourceOfLogMessage;
     Timestamp = timestamp;
     Severity = severity;
 }
示例#16
0
 public RuleAttribute(string key, Severity severity, string title, bool isActivatedByDefault)
 {
     Key = key;
     Title = title;
     Severity = severity;
     IsActivatedByDefault = isActivatedByDefault;
 }
示例#17
0
        protected override void LogMessageCore(string message, IDictionary<string, string> additionalData, Severity severity)
        {
            var output = WebUtility.HtmlEncode(message).Replace("\r\n", "<br />").Replace("\r", "<br />").Replace("\n", "<br />");
            output = $"{dateTimeNowProvider.Now:yyyy-MM-dd HH:mm:ss}<br />" + output;

            mailerService.SendMail(recipientAddress, "Error Report", output);
        }
示例#18
0
 public LogMessage(string message, IContext context, Severity severity)
 {
     Message = message;
     Severity = severity;
     Context = context;
     Time = DateTime.Now;
 }
        public override void AddError(string path, string message, string lineText, CodeSpan location, int errorCode, Severity severity)
        {
            // keep the error list under 100 items which is a reasonable number and avoids spending too much time on error processing
            if (Errors.Count < 100)
            {
                int startIndex, endIndex;
                if (location.StartLine > 0 && location.EndLine > 0)
                {
                    // get the error bounds to create a span pointing to the error text so it can be navigated to later on by the Error List
                    startIndex = textBuffer.CurrentSnapshot.GetLineFromLineNumber(location.StartLine - 1).Start.Position + location.StartColumn;
                    endIndex = textBuffer.CurrentSnapshot.GetLineFromLineNumber(location.EndLine - 1).Start.Position + location.EndColumn;

                    if (startIndex < endIndex && endIndex < textBuffer.CurrentSnapshot.GetText().Length)
                    {
                        // add the error with all its necessary information
                        Errors.Add(new ValidationError(new Span(startIndex, endIndex - startIndex), message, GetSeverity(severity), ValidationErrorType.Syntactic));

                        if (Errors.Count == 100)
                        {
                            // add a friendly error telling the user the maximum number of errors has been reached
                            Errors.Add(new ValidationError(new Span(startIndex, endIndex - startIndex), "The maximum number of errors or warnings has been reached."));
                        }
                    }
                }
            }
        }
示例#20
0
        private static void Emit(Severity s, string format, params object[] args)
        {
            lock (_consolelock)
            {
                var color = Console.ForegroundColor;
                switch (s)
                {
                    case Severity.information:
                        // Console.ForegroundColor = ConsoleColor.White;
                        break;

                    case Severity.warning:
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        break;

                    case Severity.error:
                        Console.ForegroundColor = ConsoleColor.Red;
                        break;
                }


                var msg = string.Format(format, args);
                if (Debugger.IsAttached)
                {
                    Debug.WriteLine(msg);
                }

                Console.WriteLine(msg);
                Console.ForegroundColor = color;
            }
        }
 public void TrackTrace(string message, Severity severity)
 {
     switch (severity)
     {
         case Severity.Error:
             ConsoleText.WriteError(message);
             break;
         case Severity.Info:
             ConsoleText.WriteStatus(message);
             break;
         case Severity.Verbose:
         case Severity.Verbose2:
         case Severity.Verbose3:
             ConsoleText.WriteUsage(message);
             break;
         case Severity.Warning:
             ConsoleText.WriteWarning(message);
             break;
         case Severity.Off:
             return;
         default:
             TrackTrace(message);
             break;
     }
 }
示例#22
0
        public void Write(Severity sev, string msg)
        {
            if (_isOpen == false)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("[");
            if (sev == Severity.Debug)
            {
                sb.Append("D");
            }
            else if (sev == Severity.Warning)
            {
                sb.Append("W");
            }
            else if (sev == Severity.Error)
            {
                sb.Append("E");
            }
            sb.Append("]");

            sb.Append("[");
            sb.Append(DateTime.Now.ToString("dd/MM/yy HH:mm:ss"));
            sb.Append("] ");
            sb.Append(msg);

            string line = sb.ToString ();
            _logStream.WriteLine (line);
            #if DEBUG
            Console.WriteLine (line);
            #endif
        }
示例#23
0
文件: Program.cs 项目: TerabyteX/main
            public override void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity)
            {
                base.Add(sourceUnit, message, span, errorCode, severity);

                Console.Error.WriteLine("{0}({1}:{2}): {3}: RB{4}: {5}", sourceUnit.Name, span.Start.Line, span.Start.Column,
                    severity, errorCode, message);
            }
        public static IStatusAppender Filtered(IStatusAppender baseAppender, Severity[] severities)
        {
            if (severities == null) { throw new ArgumentNullException("severities"); } // $NON-NLS-1

            if (baseAppender == null || object.ReferenceEquals(baseAppender, StatusAppender.Null)) {
                return StatusAppender.Null;
            } else if (severities.Length == 0) {
                return StatusAppender.Null;
            } else {
                // 2^0 = 1 (None)
                // 2^1 = 2 (Error)
                // 2^2 = 4 (Warning)
                // 2^3 = 8 (Information)

                int result = 0;

                for (int i = 0; i < severities.Length; i++) {
                    result &= (int) (Math.Pow(2, (int) severities[i]));
                    if (result >= 2 + 4 + 8) { // all have been set or more
                        return baseAppender;
                    }
                }

                bool appendInfos = (result & 8) > 0;
                bool appendWarnings = (result & 4) > 0;
                bool appendErrors = (result & 2) > 0;

                return new FilteredStatusAppender(baseAppender, appendErrors, appendWarnings, appendInfos);
            }
        }
示例#25
0
 public AiReportOneObject(HitObjectBase h,int time, BeenCorrectedDelegate corrected, Severity severity, string information, int weblink)
     : base(time, severity, information, weblink, corrected)
 {
     this.h1 = h;
     
     RelatedHitObjects.Add(h);
 }
示例#26
0
        protected Item( Severity severity, string message,
			object targetItem )
        {
            this.severity = severity;
            this.message = message ?? string.Empty;
            this.targetItem = targetItem;
        }
示例#27
0
        private static void Log(string str, Severity sev)
        {
            string header = string.Empty;
            switch (sev)
            {
                case Severity.TRACE:
                    header = "TT ##";
                    break;
                case Severity.INFO:
                    header = "II ##";
                    break;
                case Severity.WARNING:
                    header = "WW ##";
                    break;
                case Severity.ERROR:
                    header = "EE ##";
                    break;
                case Severity.STEPIN:
                    header = ">> ##";
                    break;
                case Severity.STEPOUT:
                    header = "<< ##";
                    break;
            }

            Reporter.Log(header + str + Environment.NewLine);
        }
        private List<ValidationIssue> ParseIssues(XContainer document, string rootName, string listName, string tagName, Severity severity)
        {
            var elements = from e in document.Descendants(_namespace + rootName) select e;
            var issues = new List<ValidationIssue>();

            foreach (var element in elements)
            {
                foreach (var list in element.Descendants(_namespace + listName))
                {
                    foreach (var errorElement in list.Descendants(_namespace + tagName))
                    {
                        var issue = new ValidationIssue { Severity = severity };

                        if (errorElement.Descendants(_namespace + "line").Any())
                            issue.Row = int.Parse(errorElement.Descendants(_namespace + "line").First().Value);
                        if (errorElement.Descendants(_namespace + "col").Any())
                            issue.Column = int.Parse(errorElement.Descendants(_namespace + "col").First().Value);
                        if (errorElement.Descendants(_namespace + "message").Any())
                        {
                            issue.Title = errorElement.Descendants(_namespace + "message").First().Value;
                            issue.MessageId = Encoding.UTF8.GetString(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(issue.Title)));
                        }

                        issues.Add(issue);
                    }
                }
            }

            return issues;
        }
示例#29
0
文件: ZeroLog.cs 项目: dzhendong/Zero
 /// <summary>
 /// Log a message.  The current logging level is used to determine
 ///		if the message is appended to the configured appender
 ///		or if it is ignored.
 /// </summary>
 /// <param name="category">The category to which this log statement belongs.</param>
 /// <param name="s">The severity of the logging message.</param>
 /// <param name="errorMsg">A concise description of the problem encountered.</param>
 /// <param name="args">Variable values that are to be captured with the logging statement.</param>
 public static void Log(Severity s, string errorMsg, params object[] args)
 {
     if (args != null && args.Length > 0)
         LogMessage(s, Format(s.ToString() + ": " + errorMsg, args), null);
     else
         LogMessage(s, errorMsg, null);
 }
示例#30
0
        public AiReportOneObject(HitObjectBase h, BeenCorrectedDelegate corrected, Severity severity, string information, int weblink, GameMode Mode = GameMode.All)
            : base(h.StartTime, severity, information, weblink, corrected, Mode)
        {
            this.h1 = h;

            RelatedHitObjects.Add(h);
        }
示例#31
0
        public SyntaxErrorException(string message, string path, string code, string line, SourceSpan span, int errorCode, Severity severity)
            : base(message)
        {
            ContractUtils.RequiresNotNull(message, nameof(message));

            _span      = span;
            _severity  = severity;
            _errorCode = errorCode;

            _sourcePath = path;
            _sourceCode = code;
            _sourceLine = line;
        }
示例#32
0
 public override void AddError(string path, string message, string lineText, int startLine, int startColumn, int endLine, int endColumn, int errorCode, Severity severity)
 {
     compResults.Errors.Add(new CompilerError(path, startLine, startColumn, errorCode.ToString(), message));
     throw new CompilerException();
 }
示例#33
0
 /// <inheritdoc />
 public void Log(Severity severity, string message) => _logger.Log(severity, message);
示例#34
0
 /// <inheritdoc />
 public InspectableConsoleLog(Severity severity = Severity.Diagnostic, bool useShortLayout = true, bool printSeverity = false)
     : base(severity, useShortLayout, printSeverity)
 {
 }
 public void TrackTrace(string message, Severity severityLevel, IDictionary <string, string> properties)
 {
     throw new NotImplementedException();
 }
示例#36
0
 public virtual void Add(string message, SourceSpan span, int errorCode, Severity severity)
 {
 }
示例#37
0
 internal void Add(string message, SourceLocation startSourceLoc, SourceLocation endSourceLoc, int errorCode, Severity severity) => Add(
     message,
     new SourceSpan(startSourceLoc, endSourceLoc),
     errorCode,
     severity
     );
示例#38
0
 internal void Add(string message, NewLineLocation[] lineLocations, int startIndex, int endIndex, int errorCode, Severity severity) => Add(
     message,
     NewLineLocation.IndexToLocation(lineLocations, startIndex),
     NewLineLocation.IndexToLocation(lineLocations, endIndex),
     errorCode,
     severity
     );
示例#39
0
 /// <inheritdoc />
 public void LogFormat(Severity severity, string messageFormat, params object[] messageArgs) => _logger.LogFormat(severity, messageFormat, messageArgs);
示例#40
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="RollingMemoryLog" /> class.
 /// </summary>
 /// <param name="severity">Logging severity to use.</param>
 public RollingMemoryLog(Severity severity)
 {
     CurrentSeverity = severity;
 }
示例#41
0
 private void Log(Severity severity, string message, params object[] args)
 {
     Log(severity, String.Format(message, args));
 }
示例#42
0
        /// <summary>
        /// Generate LogContext structure based on executionContext and invocationInfo passed in.
        ///
        /// LogContext structure is used in log provider interface.
        /// </summary>
        /// <param name="executionContext"></param>
        /// <param name="invocationInfo"></param>
        /// <param name="severity"></param>
        /// <returns></returns>
        private static LogContext GetLogContext(ExecutionContext executionContext, InvocationInfo invocationInfo, Severity severity)
        {
            if (executionContext == null)
            {
                return(null);
            }

            LogContext logContext = new LogContext();

            string shellId = executionContext.ShellID;

            logContext.ExecutionContext = executionContext;
            logContext.ShellId          = shellId;
            logContext.Severity         = severity.ToString();

            if (executionContext.EngineHostInterface != null)
            {
                logContext.HostName    = executionContext.EngineHostInterface.Name;
                logContext.HostVersion = executionContext.EngineHostInterface.Version.ToString();
                logContext.HostId      = (string)executionContext.EngineHostInterface.InstanceId.ToString();
            }

            logContext.HostApplication = string.Join(" ", Environment.GetCommandLineArgs());

            if (executionContext.CurrentRunspace != null)
            {
                logContext.EngineVersion = executionContext.CurrentRunspace.Version.ToString();
                logContext.RunspaceId    = executionContext.CurrentRunspace.InstanceId.ToString();

                Pipeline currentPipeline = ((RunspaceBase)executionContext.CurrentRunspace).GetCurrentlyRunningPipeline();
                if (currentPipeline != null)
                {
                    logContext.PipelineId = currentPipeline.InstanceId.ToString(CultureInfo.CurrentCulture);
                }
            }

            logContext.SequenceNumber = NextSequenceNumber;

            try
            {
                if (executionContext.LogContextCache.User == null)
                {
                    logContext.User = Environment.UserDomainName + "\\" + Environment.UserName;
                    executionContext.LogContextCache.User = logContext.User;
                }
                else
                {
                    logContext.User = executionContext.LogContextCache.User;
                }
            }
            catch (InvalidOperationException)
            {
                logContext.User = Logging.UnknownUserName;
            }

            System.Management.Automation.Remoting.PSSenderInfo psSenderInfo =
                executionContext.SessionState.PSVariable.GetValue("PSSenderInfo") as System.Management.Automation.Remoting.PSSenderInfo;
            if (psSenderInfo != null)
            {
                logContext.ConnectedUser = psSenderInfo.UserInfo.Identity.Name;
            }

            logContext.Time = DateTime.Now.ToString(CultureInfo.CurrentCulture);

            if (invocationInfo == null)
            {
                return(logContext);
            }

            logContext.ScriptName  = invocationInfo.ScriptName;
            logContext.CommandLine = invocationInfo.Line;

            if (invocationInfo.MyCommand != null)
            {
                logContext.CommandName = invocationInfo.MyCommand.Name;
                logContext.CommandType = invocationInfo.MyCommand.CommandType.ToString();

                switch (invocationInfo.MyCommand.CommandType)
                {
                case CommandTypes.Application:
                    logContext.CommandPath = ((ApplicationInfo)invocationInfo.MyCommand).Path;
                    break;

                case CommandTypes.ExternalScript:
                    logContext.CommandPath = ((ExternalScriptInfo)invocationInfo.MyCommand).Path;
                    break;
                }
            }

            return(logContext);
        }
示例#43
0
 public void Write(Severity level, object context, string format, params object[] args)
 {
     WriteCore(level, context, format.Localized(args));
 }
示例#44
0
        public SyntaxErrorException(string message, SourceUnit sourceUnit, SourceSpan span, int errorCode, Severity severity)
            : base(message)
        {
            ContractUtils.RequiresNotNull(message, nameof(message));

            _span      = span;
            _severity  = severity;
            _errorCode = errorCode;
            if (sourceUnit != null)
            {
                _sourcePath = sourceUnit.Path;
                try {
                    _sourceCode = sourceUnit.GetCode();
                    _sourceLine = sourceUnit.GetCodeLine(Line);
                } catch (System.IO.IOException) {
                    // could not get source code.
                }
            }
        }
示例#45
0
 public void Write(Severity level, object context, string format)
 {
     WriteCore(level, context, format.Localized());
 }
示例#46
0
 /// <summary>
 /// This is a variation of LogEngineHealthEvent api to make eventid, additionalInfo and newEngineState
 /// optional.
 ///
 /// A default event id for engine health event will be used.
 /// </summary>
 /// <param name="executionContext"></param>
 /// <param name="exception"></param>
 /// <param name="severity"></param>
 internal static void LogEngineHealthEvent(ExecutionContext executionContext,
                                           Exception exception,
                                           Severity severity)
 {
     LogEngineHealthEvent(executionContext, 100, exception, severity, null);
 }
示例#47
0
 /// <summary>Always returns true.</summary>
 public bool IsEnabled(Severity type)
 {
     return(true);
 }
示例#48
0
 public void Write(Severity level, object context, string format, object arg0, object arg1 = null)
 {
     WriteCore(level, context, format.Localized(arg0, arg1));
 }
示例#49
0
 public void Write(Severity type, object context, string format, object arg0, object arg1 = null)
 {
     WriteCore(type, context, Localize.Localized(format, arg0, arg1));
 }
示例#50
0
 public bool IsEnabled(Severity level)
 {
     return(_isEnabled != null?_isEnabled(level) : true);
 }
示例#51
0
 /// <summary>Always returns false.</summary>
 public bool IsEnabled(Severity level)
 {
     return(false);
 }
示例#52
0
 public void Write(Severity type, object context, string format, params object[] args)
 {
     WriteCore(type, context, Localize.Localized(format, args));
 }
示例#53
0
 public void Write(Severity level, object context, string format, object arg0, object arg1 = null)
 {
     Write(level, context, format);
 }
示例#54
0
 public void Write(Severity type, object context, string format)
 {
     WriteCore(type, context, Localize.Localized(format));
 }
示例#55
0
 public void SetLogFileSeverity(Severity severity)
 {
     _fileLogSeverity = severity;
 }
示例#56
0
 public void Write(Severity level, object context, string format, params object[] args)
 {
     Write(level, context, format);
 }
示例#57
0
 /// <summary>
 ///     Check if a given severity level is current enabled for tracing.
 /// </summary>
 public bool IsSeverityEnabled(Severity severity)
 {
     return(IsEnabled && severity >= Logger.CurrentSeverity);
 }
示例#58
0
 /// <summary>Always returns true.</summary>
 public bool IsEnabled(Severity level)
 {
     return(true);
 }
示例#59
0
        /// <summary>
        /// Trace operation completion.
        /// </summary>
        public void OperationFinished(string message, string operationName, string componentName, ResultBase result, TimeSpan duration, Severity successSeverity, OperationKind kind)
        {
            // Severity level for non-successful case is computed in the following way:
            // CriticalFailures -> Error
            // Non-critical errors during initialization -> Warning
            // Non-critical errors in all the other operations -> Info

            var severity = successSeverity;

            if (!result.Succeeded)
            {
                severity = result.IsCriticalFailure ? Severity.Error : (kind == OperationKind.Startup ? Severity.Warning : Severity.Info);
            }

            TraceMessage(severity, message);

            if (Logger is IOperationLogger operationLogger)
            {
                var operationResult = new OperationResult(message, operationName, componentName, statusFromResult(result), duration, kind, result.Exception);
                operationLogger.OperationFinished(operationResult);
            }

            OperationStatus statusFromResult(ResultBase resultBase)
            {
                if (resultBase.IsCriticalFailure)
                {
                    return(OperationStatus.CriticalFailure);
                }
                else if (resultBase.IsCancelled)
                {
                    return(OperationStatus.Cancelled);
                }
                else if (resultBase.HasException)
                {
                    return(OperationStatus.Failure);
                }
                else
                {
                    return(OperationStatus.Success);
                }
            }
        }
 ///<summary>
 /// Specifies custom severity that should be stored alongside the validation message when validation fails for this rule.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="TProperty"></typeparam>
 /// <param name="rule"></param>
 /// <param name="severity"></param>
 /// <returns></returns>
 public static IRuleBuilderOptions <T, TProperty> WithSeverity <T, TProperty>(this IRuleBuilderOptions <T, TProperty> rule, Severity severity)
 {
     return(rule.Configure(config => config.CurrentValidator.Options.Severity = severity));
 }