コード例 #1
0
ファイル: LoggerExtensions.cs プロジェクト: jdaigle/LightRail
 public static void Log(this ILogger logger, LoggingEventType eventType, Exception exception, string message, params object[] formatArgs)
 {
     if (logger.IsLogEventEnabled(eventType))
     {
         logger.Log(new LogEntry(eventType, string.Format(message, formatArgs), exception));
     }
 }
コード例 #2
0
        public void Log_WithValidArguments_Succeeds()
        {
            // Arrange
            LoggingEventType validSeverity = LoggingEventType.Critical;
            string           validMessage  = "Valid message";
            MethodBase       validSource   = MethodBase.GetCurrentMethod();

            // Act
            Logger.Log(validSeverity, validMessage, validSource);
        }
コード例 #3
0
        /// <summary>Logs an event to the wrapped <see cref="Logger"/>.</summary>
        /// <param name="logger">The logger.</param>
        /// <param name="severity">The severity of the event.</param>
        /// <param name="message">The description of the event.</param>
        /// <param name="source">A source where the event occurred.</param>
        /// <returns>The id of the logged event or null in one of the following reasons:
        /// The event hasn't been logged, because of the current
        /// <see cref="LoggingProviderBase.Threshold">Threshold</see> level;
        /// Returning an id is not supported by the current implementation;
        /// The event has been logged to a fallback provider, because of an error in the current implementation.
        /// </returns>
        /// <exception cref="ArgumentException">Thrown when the supplied <paramref name="message"/> or
        /// <paramref name="source"/> are empty strings.</exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown when the supplied <paramref name="message"/>, <paramref name="source"/> or
        /// <paramref name="logger"/> are null references (Nothing in VB).</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when the supplied <paramref name="severity"/>
        /// has an unexpected value.</exception>
        /// <exception cref="Exception">Thrown when the logging provider failed to log the event. The
        /// exact type of exception thrown depends on the actual provider implementation. See documentation
        /// of the <see cref="LoggingProviderBase.LogInternal">LogInternal</see> method of the used logging
        /// provider for more information.</exception>
        public static object Log(this ILogger logger, LoggingEventType severity, string message, string source)
        {
            LoggingHelper.ValideLoggerIsNotNull(logger);
            LoggingHelper.ValidateSeverityInValidRange(severity);
            LoggingHelper.ValidateSourceNotNullOrEmpty(source);

            LogEntry entry = new LogEntry(severity, message, source, null);

            return(logger.Log(entry));
        }
コード例 #4
0
        public void Log_WithInvalidSeverity_ThrowsException()
        {
            // Arrange
            LoggingEventType invalidSeverity = (LoggingEventType)6;
            string           validMessage    = "Valid message";
            MethodBase       validSource     = MethodBase.GetCurrentMethod();

            // Act
            Logger.Log(invalidSeverity, validMessage, validSource);
        }
コード例 #5
0
        public void Log_WithEmptyMessage_ThrowsException()
        {
            // Arrange
            LoggingEventType validSeverity  = LoggingEventType.Critical;
            string           invalidMessage = string.Empty;
            MethodBase       validSource    = MethodBase.GetCurrentMethod();

            // Act
            Logger.Log(validSeverity, invalidMessage, validSource);
        }
コード例 #6
0
        public void Log_WithValidArguments_Succeeds()
        {
            // Arrange
            LoggingEventType validSeverity = LoggingEventType.Critical;
            string           validMessage  = "Valid message";
            string           validSource   = "Valid source";

            // Act
            Logger.Log(validSeverity, validMessage, validSource);
        }
コード例 #7
0
        public void Log_WithInvalidSeverity_ThrowsException()
        {
            // Arrange
            LoggingEventType invalidSeverity = (LoggingEventType)6;
            string           validMessage    = "Valid message";
            string           validSource     = "Valid source";

            // Act
            Logger.Log(invalidSeverity, validMessage, validSource);
        }
コード例 #8
0
        public void Log_WithNullMessage_ThrowsException()
        {
            // Arrange
            LoggingEventType validSeverity  = LoggingEventType.Critical;
            string           invalidMessage = null;
            string           validSource    = "Valid source";

            // Act
            Logger.Log(validSeverity, invalidMessage, validSource);
        }
コード例 #9
0
        /// <summary>
        /// Adds an entry to the log.
        /// </summary>
        /// <param name="severity">The type of event to log.</param>
        /// <param name="message">The message to log.</param>
        /// <param name="exception">The exception (optional).</param>
        public LogEntry(LoggingEventType severity, string message, Exception exception = null)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            Severity  = severity;
            Message   = message;
            Exception = exception;
        }
コード例 #10
0
 /// <summary>
 /// Writes the message.
 /// </summary>
 /// <param name="logLevel">The log level.</param>
 /// <param name="message">The message function.</param>
 /// <param name="exception">The exception.</param>
 private static void WriteMessageConsole(
     LoggingEventType logLevel,
     string message,
     Exception exception)
 {
     if (exception != null)
     {
         message = message + "|" + exception;
     }
     Console.WriteLine("{0} | {1} | {2}", DateTime.UtcNow, logLevel, message);
 }
コード例 #11
0
ファイル: ILibraryLogger.cs プロジェクト: Yuhis/tanssikisa
        public LogEntry(LoggingEventType severity, string message, Exception exception = null)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentNullException("message");
            }

            this.Severity  = severity;
            this.Message   = message;
            this.Exception = exception;
        }
コード例 #12
0
        public MailLoggingProvider(LoggingEventType threshold, string subjectFormatString,
                                   LoggingProviderBase fallbackProvider, params MailAddress[] recipients)
            : base(threshold, fallbackProvider)
        {
            this.To = BuildAddressList(recipients);

            this.ValidateSubjectFormatString(subjectFormatString, InitializationModel.CodeOnly);
            this.SetSubjectFormatString(subjectFormatString);

            this.ValidateDotNetMailConfiguration();
        }
コード例 #13
0
        public static ILogger Create(string queueName, LoggingEventType logLevel, string initText)
        {
            if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\Logs\\"))
            {
                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\Logs\\");
            }

            return
                (new TextFileLogProvider(
                     AppDomain.CurrentDomain.BaseDirectory + $"\\Logs\\{queueName}.txt", logLevel, initText));
        }
コード例 #14
0
 internal static LogLevel ToNLogSeverity(this LoggingEventType severity)
 {
     return(severity switch
     {
         LoggingEventType.Debug => LogLevel.Debug,
         LoggingEventType.Information => LogLevel.Info,
         LoggingEventType.Warning => LogLevel.Warn,
         LoggingEventType.Error => LogLevel.Error,
         LoggingEventType.Fatal => LogLevel.Fatal,
         _ => throw new ArgumentOutOfRangeException(nameof(severity), severity, null)
     });
コード例 #15
0
ファイル: LogEntry.cs プロジェクト: nikkonrom/drawiosharing
        public LogEntry(LoggingEventType loggingEventType, string message, Exception exception = null)
        {
            if (String.IsNullOrEmpty(message))
            {
                // ReSharper disable once NotResolvedInText
                throw new ArgumentNullException("Log message is null or empty");
            }

            LoggingEventType = loggingEventType;
            Message          = message;
            Exception        = exception;
        }
コード例 #16
0
ファイル: SerilogBuilder.cs プロジェクト: Pastafarian/DevBlog
 private static LogEventLevel MapLogEventLevel(LoggingEventType type)
 {
     return(type switch
     {
         LoggingEventType.Verbose => LogEventLevel.Verbose,
         LoggingEventType.Debug => LogEventLevel.Debug,
         LoggingEventType.Information => LogEventLevel.Information,
         LoggingEventType.Warning => LogEventLevel.Warning,
         LoggingEventType.Error => LogEventLevel.Error,
         LoggingEventType.Fatal => LogEventLevel.Fatal,
         _ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
     });
コード例 #17
0
 NLog.LogLevel GetNLogLevel(LoggingEventType level)
 {
     switch (level)
     {
        case LoggingEventType.Debug: return NLog.LogLevel.Debug;
        case LoggingEventType.Information: return NLog.LogLevel.Info;
        case LoggingEventType.Warning: return NLog.LogLevel.Warn;
        case LoggingEventType.Error: return NLog.LogLevel.Error;
        case LoggingEventType.Fatal: return NLog.LogLevel.Fatal;
        default: return NLog.LogLevel.Trace;
     }
 }
コード例 #18
0
        private static LogEntry CreateLogEntry(WebBaseEvent eventRaised)
        {
            LoggingEventType eventType = GetEventTypeFromWebEvent(eventRaised);

            string message = string.Format(CultureInfo.InvariantCulture, "{0} (Event Code: {1})",
                                           eventRaised.Message, eventRaised.EventCode);

            string source = eventRaised.GetType().Name;

            Exception exception = GetExceptionFromWebEvent(eventRaised);

            return(new LogEntry(eventType, message, source, exception));
        }
コード例 #19
0
        /// <summary>Logs an event to the wrapped <see cref="Logger"/>.</summary>
        /// <param name="logger">The logger.</param>
        /// <param name="severity">The severity of the event.</param>
        /// <param name="message">The description of the event.</param>
        /// <param name="source">A source where the event occurred.</param>
        /// <returns>The id of the logged event or null in one of the following reasons:
        /// The event hasn't been logged, because of the current
        /// <see cref="LoggingProviderBase.Threshold">Threshold</see> level;
        /// Returning an id is not supported by the current implementation;
        /// The event has been logged to a fallback provider, because of an error in the current implementation.
        /// </returns>
        /// <exception cref="ArgumentException">Thrown when the supplied <paramref name="message"/> is
        /// an empty string.</exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown when the supplied <paramref name="message"/>, <paramref name="source"/> or
        /// <paramref name="logger"/> are null references (Nothing in VB).</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when the supplied <paramref name="severity"/>
        /// has an unexpected value.</exception>
        /// <exception cref="Exception">Thrown when the logging provider failed to log the event. The
        /// exact type of exception thrown depends on the actual provider implementation. See documentation
        /// of the <see cref="LoggingProviderBase.LogInternal">LogInternal</see> method of the used logging
        /// provider for more information.</exception>
        public static object Log(this ILogger logger, LoggingEventType severity, string message,
                                 MethodBase source)
        {
            LoggingHelper.ValideLoggerIsNotNull(logger);
            LoggingHelper.ValidateSeverityInValidRange(severity);
            LoggingHelper.ValidateSourceIsNotNull(source);

            string methodName = LoggingHelper.BuildMethodName(source);

            LogEntry entry = new LogEntry(severity, message, methodName, null);

            return(logger.Log(entry));
        }
コード例 #20
0
        /// <summary>Initializes a new instance of the <see cref="SqlLoggingProvider"/> class.</summary>
        /// <param name="threshold">The <see cref="LoggingEventType"/> logging threshold. The threshold limits
        /// the number of event logged. <see cref="LoggingProviderBase.Threshold">Threshold</see> for more
        /// information.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="fallbackProvider">The optional fallback provider.</param>
        /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="threshold"/> has an
        /// invalid value.</exception>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="connectionString"/> is a
        /// null reference (Nothing in VB).</exception>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="connectionString"/> is an
        /// empty string.</exception>
        public SqlLoggingProvider(LoggingEventType threshold, string connectionString,
                                  LoggingProviderBase fallbackProvider) : base(threshold, fallbackProvider)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }

            if (connectionString.Length == 0)
            {
                throw new ArgumentException(SR.ValueShouldNotBeAnEmptyString(), "connectionString");
            }

            this.connectionString = connectionString;
        }
コード例 #21
0
        /// <summary>Initializes a new instance of the <see cref="LoggingProviderBase"/> class.</summary>
        /// <param name="threshold">The <see cref="LoggingEventType"/> logging threshold. The threshold limits
        /// the number of event logged. <see cref="Threshold"/> for more information.</param>
        /// <param name="fallbackProvider">The optional fallback provider.</param>
        /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="threshold"/> has an
        /// invalid value.</exception>
        protected LoggingProviderBase(LoggingEventType threshold, LoggingProviderBase fallbackProvider)
        {
            if (threshold < LoggingEventType.Debug || threshold > LoggingEventType.Critical)
            {
                throw new InvalidEnumArgumentException("threshold", (int)threshold, typeof(LoggingEventType));
            }

            base.Initialize(this.GetType().Name, null);

            this.threshold = threshold;

            // NOTE: We don't have to check for circular references, because a provider is immutable after
            // creation and can therefore never be circular referencing itself.
            this.FallbackProvider = fallbackProvider;
        }
コード例 #22
0
ファイル: LogEntry.cs プロジェクト: Murat-Ozcan/MrtLog
        public LogEntry(LoggingEventType severity, string message, Exception exception = null)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (message == string.Empty)
            {
                throw new ArgumentException("empty", "message");
            }

            this.Severity  = severity;
            this.Message   = message;
            this.Exception = exception;
        }
コード例 #23
0
ファイル: ILogger.cs プロジェクト: hectorballon/Lumini
        public LogEntry(LoggingEventType severity, string message, Exception exception = null)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (message == string.Empty)
            {
                throw new ArgumentException("empty", nameof(message));
            }

            Severity  = severity;
            Message   = message;
            Exception = exception;
        }
コード例 #24
0
        private static ILog GetLoggerWithThreshold(LoggingEventType threshold)
        {
            var loggingProvider =
                (from provider in Logger.Providers
                 where provider.Threshold == threshold
                 select provider).FirstOrDefault();

            if (loggingProvider == null)
            {
                Assert.Fail("No LoggingProvider with threshold of {0} was found.", threshold);
            }

            var adapter = new CuttingEdgeLoggerFactoryAdapter();

            return(adapter.GetLogger(loggingProvider.Name));
        }
コード例 #25
0
        public LogEntry(Type callingType, LoggingEventType severity, string message, Exception exception = null)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (message == string.Empty)
            {
                throw new ArgumentException("empty", "message");
            }

            CallingType = callingType;
            Severity    = severity;
            Message     = message;
            Exception   = exception;
        }
コード例 #26
0
        public LogEntry(LoggingEventType severity, string message, Exception exception = null, params object[] args)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (message == string.Empty)
            {
                throw new ArgumentException("message cannot be empty", "message");
            }

            Severity  = severity;
            Message   = message;
            Exception = exception;
            Args      = args;
        }
コード例 #27
0
        public LogEntry(LoggingEventType severity, string messageTemplate, Dictionary <string, object> properties = null, Exception exception = null)
        {
            if (messageTemplate == null)
            {
                throw new ArgumentNullException(nameof(messageTemplate));
            }
            if (messageTemplate == string.Empty)
            {
                throw new ArgumentException("Message Template cannot be empty.", nameof(messageTemplate));
            }

            Severity        = severity;
            MessageTemplate = messageTemplate;
            Exception       = exception;
            Properties      = properties ?? new Dictionary <string, object>();
        }
コード例 #28
0
    NLog.LogLevel GetNLogLevel(LoggingEventType level)
    {
        switch (level)
        {
        case LoggingEventType.Debug: return(NLog.LogLevel.Debug);

        case LoggingEventType.Information: return(NLog.LogLevel.Info);

        case LoggingEventType.Warning: return(NLog.LogLevel.Warn);

        case LoggingEventType.Error: return(NLog.LogLevel.Error);

        case LoggingEventType.Fatal: return(NLog.LogLevel.Fatal);

        default: return(NLog.LogLevel.Trace);
        }
    }
コード例 #29
0
 private ConsoleColors GetLogLevelConsoleColors(LoggingEventType logLevel)
 {
     // do not change user's background color except for Critical
     switch (logLevel)
     {
         case LoggingEventType.Fatal:
             return new ConsoleColors(ConsoleColor.White, ConsoleColor.Red);
         case LoggingEventType.Error:
             return new ConsoleColors(ConsoleColor.Red, defaultConsoleColor);
         case LoggingEventType.Warning:
             return new ConsoleColors(ConsoleColor.DarkYellow, defaultConsoleColor);
         case LoggingEventType.Information:
             return new ConsoleColors(ConsoleColor.DarkGreen, defaultConsoleColor);
         default:
             return new ConsoleColors(ConsoleColor.Gray, defaultConsoleColor);
     }
 }
コード例 #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AspNetSqlLoggingProvider"/> class.
        /// </summary>
        /// <param name="threshold">The <see cref="LoggingEventType"/> logging threshold. The threshold limits
        /// the number of event logged. <see cref="LoggingProviderBase.Threshold">Threshold</see> for more
        /// information.</param>
        /// <param name="configuration">The configuration that initializes this provider.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="fallbackProvider">The optional fallback provider.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="connectionString"/> or the
        /// <paramref name="configuration"/> are null references (Nothing in VB).</exception>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="connectionString"/> is an
        /// empty string.</exception>
        public AspNetSqlLoggingProvider(LoggingEventType threshold,
                                        AspNetSqlLoggingProviderConfiguration configuration, string connectionString,
                                        LoggingProviderBase fallbackProvider)
            : base(threshold, connectionString, fallbackProvider)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            // We don't have to validate the configuration properties, because the configuration already did
            // this itself.
            this.logQueryString  = configuration.LogQueryString;
            this.logFormData     = configuration.LogFormData;
            this.applicationName = configuration.ApplicationName;
            this.retrievalType   = configuration.RetrievalType;
        }
コード例 #31
0
ファイル: LogMessagePacketBase.cs プロジェクト: 3F/IeXod
        /// <summary>
        /// Given a build event that is presumed to be 2.0 (due to its lack of a "ReadFromStream" method) and its
        /// LoggingEventType, read that event from the stream.
        /// </summary>
        private BuildEventArgs ReadEventFromStream(LoggingEventType eventType, ITranslator translator)
        {
            string message     = null;
            string helpKeyword = null;
            string senderName  = null;

            translator.Translate(ref message);
            translator.Translate(ref helpKeyword);
            translator.Translate(ref senderName);

            BuildEventArgs buildEvent = null;

            switch (eventType)
            {
            case LoggingEventType.TaskCommandLineEvent:
                buildEvent = ReadTaskCommandLineEventFromStream(translator, message, helpKeyword, senderName);
                break;

            case LoggingEventType.BuildErrorEvent:
                buildEvent = ReadTaskBuildErrorEventFromStream(translator, message, helpKeyword, senderName);
                break;

            case LoggingEventType.ProjectStartedEvent:
                buildEvent = ReadExternalProjectStartedEventFromStream(translator, message, helpKeyword, senderName);
                break;

            case LoggingEventType.ProjectFinishedEvent:
                buildEvent = ReadExternalProjectFinishedEventFromStream(translator, message, helpKeyword, senderName);
                break;

            case LoggingEventType.BuildMessageEvent:
                buildEvent = ReadBuildMessageEventFromStream(translator, message, helpKeyword, senderName);
                break;

            case LoggingEventType.BuildWarningEvent:
                buildEvent = ReadBuildWarningEventFromStream(translator, message, helpKeyword, senderName);
                break;

            default:
                ErrorUtilities.ThrowInternalError("Not Supported LoggingEventType {0}", eventType.ToString());
                break;
            }

            return(buildEvent);
        }
コード例 #32
0
ファイル: NodeLoggingEvent.cs プロジェクト: xen2/msbuild
        /// <summary>
        /// Takes in a id (LoggingEventType as an int) and creates the correct specific logging class
        /// </summary>
        private BuildEventArgs GetBuildEventArgFromId(LoggingEventType id)
        {
            switch (id)
            {
            case LoggingEventType.BuildErrorEvent:
                return(new BuildErrorEventArgs(null, null, null, -1, -1, -1, -1, null, null, null));

            case LoggingEventType.BuildFinishedEvent:
                return(new BuildFinishedEventArgs(null, null, false));

            case LoggingEventType.BuildMessageEvent:
                return(new BuildMessageEventArgs(null, null, null, MessageImportance.Normal));

            case LoggingEventType.BuildStartedEvent:
                return(new BuildStartedEventArgs(null, null));

            case LoggingEventType.BuildWarningEvent:
                return(new BuildWarningEventArgs(null, null, null, -1, -1, -1, -1, null, null, null));

            case LoggingEventType.ProjectFinishedEvent:
                return(new ProjectFinishedEventArgs(null, null, null, false));

            case LoggingEventType.ProjectStartedEvent:
                return(new ProjectStartedEventArgs(-1, null, null, null, null, null, null, null));

            case LoggingEventType.TargetStartedEvent:
                return(new TargetStartedEventArgs(null, null, null, null, null));

            case LoggingEventType.TargetFinishedEvent:
                return(new TargetFinishedEventArgs(null, null, null, null, null, false));

            case LoggingEventType.TaskStartedEvent:
                return(new TaskStartedEventArgs(null, null, null, null, null));

            case LoggingEventType.TaskFinishedEvent:
                return(new TaskFinishedEventArgs(null, null, null, null, null, false));

            case LoggingEventType.TaskCommandLineEvent:
                return(new TaskCommandLineEventArgs(null, null, MessageImportance.Normal));

            default:
                ErrorUtilities.VerifyThrow(false, "Should not get to the default of getBuildEventArgFromId ID:" + id);
                return(null);
            }
        }
コード例 #33
0
ファイル: NLogLogger.cs プロジェクト: jdaigle/LightRail
 public bool IsLogEventEnabled(LoggingEventType eventType)
 {
     switch (eventType)
     {
         case LoggingEventType.Debug:
             return logger.IsDebugEnabled;
         case LoggingEventType.Info:
             return logger.IsInfoEnabled;
         case LoggingEventType.Warn:
             return logger.IsWarnEnabled;
         case LoggingEventType.Error:
             return logger.IsErrorEnabled;
         case LoggingEventType.Fatal:
             return logger.IsFatalEnabled;
         default:
             return false;
     }
 }
コード例 #34
0
ファイル: LogEntry.cs プロジェクト: jdaigle/LightRail
        public LogEntry(LoggingEventType eventType, string message, Exception exception)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentException(nameof(message));
            }
            if (eventType < LoggingEventType.Debug || eventType > LoggingEventType.Fatal)
            {
                throw new ArgumentOutOfRangeException(nameof(eventType));
            }

            this.EventType = eventType;
            this.Message = message;
            this.Exception = exception;
        }
コード例 #35
0
ファイル: LogEntry.cs プロジェクト: superkarn/RatanaLibrary
        public LogEntry(LoggingEventType severity, string message, string source, Exception exception)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentException("message");
            }

            if (severity < LoggingEventType.Verbose || severity > LoggingEventType.Fatal)
            {
                throw new ArgumentOutOfRangeException("severity");
            }

            this.Severity = severity;
            this.Message = message;
            this.Source = source;
            this.Exception = exception;
        }
コード例 #36
0
        /// <summary>
        /// Given a build event that is presumed to be 2.0 (due to its lack of a "WriteToStream" method) and its 
        /// LoggingEventType, serialize that event to the stream. 
        /// </summary>
        private void WriteEventToStream(BuildEventArgs buildEvent, LoggingEventType eventType, INodePacketTranslator translator)
        {
            string message = buildEvent.Message;
            string helpKeyword = buildEvent.HelpKeyword;
            string senderName = buildEvent.SenderName;

            translator.Translate(ref message);
            translator.Translate(ref helpKeyword);
            translator.Translate(ref senderName);

            // It is essential that you translate in the same order during writing and reading
            switch (eventType)
            {
                case LoggingEventType.BuildMessageEvent:
                    WriteBuildMessageEventToStream((BuildMessageEventArgs)buildEvent, translator);
                    break;
                case LoggingEventType.TaskCommandLineEvent:
                    WriteTaskCommandLineEventToStream((TaskCommandLineEventArgs)buildEvent, translator);
                    break;
                case LoggingEventType.BuildErrorEvent:
                    WriteBuildErrorEventToStream((BuildErrorEventArgs)buildEvent, translator);
                    break;
                case LoggingEventType.BuildWarningEvent:
                    WriteBuildWarningEventToStream((BuildWarningEventArgs)buildEvent, translator);
                    break;
                case LoggingEventType.ProjectStartedEvent:
                    WriteExternalProjectStartedEventToStream((ExternalProjectStartedEventArgs)buildEvent, translator);
                    break;
                case LoggingEventType.ProjectFinishedEvent:
                    WriteExternalProjectFinishedEventToStream((ExternalProjectFinishedEventArgs)buildEvent, translator);
                    break;
                default:
                    ErrorUtilities.ThrowInternalError("Not Supported LoggingEventType {0}", eventType.ToString());
                    break;
            }
        }
コード例 #37
0
ファイル: NodeLoggingEvent.cs プロジェクト: nikson/msbuild
 /// <summary>
 /// Takes in a id (LoggingEventType as an int) and creates the correct specific logging class
 /// </summary>
 private BuildEventArgs GetBuildEventArgFromId(LoggingEventType id)
 {
     switch (id)
     {
         case LoggingEventType.BuildErrorEvent:
             return new BuildErrorEventArgs(null, null, null, -1, -1, -1, -1, null, null, null);
         case LoggingEventType.BuildFinishedEvent:
             return new BuildFinishedEventArgs(null, null, false);
         case LoggingEventType.BuildMessageEvent:
             return new BuildMessageEventArgs(null, null, null, MessageImportance.Normal);
         case LoggingEventType.BuildStartedEvent:
             return new BuildStartedEventArgs(null, null);
         case LoggingEventType.BuildWarningEvent:
             return new BuildWarningEventArgs(null, null, null, -1, -1, -1, -1,null,null,null);
         case LoggingEventType.ProjectFinishedEvent:
             return new ProjectFinishedEventArgs(null, null, null, false);
         case LoggingEventType.ProjectStartedEvent:
             return new ProjectStartedEventArgs(-1, null, null, null, null, null, null, null);
         case LoggingEventType.TargetStartedEvent:
             return new TargetStartedEventArgs(null, null, null, null, null);
         case LoggingEventType.TargetFinishedEvent:
             return new TargetFinishedEventArgs(null, null, null, null, null, false);
         case LoggingEventType.TaskStartedEvent:
             return new TaskStartedEventArgs(null, null, null, null, null);
         case LoggingEventType.TaskFinishedEvent:
             return new TaskFinishedEventArgs(null, null, null, null, null, false);
         case LoggingEventType.TaskCommandLineEvent:
             return new TaskCommandLineEventArgs(null, null, MessageImportance.Normal);
         default:
             ErrorUtilities.VerifyThrow(false, "Should not get to the default of getBuildEventArgFromId ID:" + id);
             return null;
     }
 }
コード例 #38
0
 /// <summary>
 /// Log with specified severity.
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="severity"></param>
 /// <param name="message"></param>
 /// <param name="source"></param>
 /// <param name="exception"></param>
 public static void Log(this ILogger logger, LoggingEventType severity, string message, string source = null, Exception exception = null)
 {
     logger.Log(new LogEntry(severity, message, source, exception));
 }
コード例 #39
0
ファイル: ConsoleLogger.cs プロジェクト: jdaigle/LightRail
 public bool IsLogEventEnabled(LoggingEventType eventType)
 {
     return true;
 }
コード例 #40
0
 /// <summary>
 /// Verify the LoggingMessagePacket is properly created from a build event. 
 /// This includes the packet type and the event type depending on which build event arg is passed in.
 /// </summary>
 /// <param name="buildEvent">Build event to put into a packet, and verify after packet creation</param>
 /// <param name="logEventType">What is the expected logging event type</param>
 private static void VerifyLoggingPacket(BuildEventArgs buildEvent, LoggingEventType logEventType)
 {
     LogMessagePacket packet = new LogMessagePacket(new KeyValuePair<int, BuildEventArgs>(0, buildEvent));
     Assert.Equal(logEventType, packet.EventType);
     Assert.Equal(NodePacketType.LogMessage, packet.Type);
     Assert.True(Object.ReferenceEquals(buildEvent, packet.NodeBuildEvent.Value.Value)); // "Expected buildEvent to have the same object reference as packet.BuildEvent"
 }
コード例 #41
0
        /// <summary>
        /// Reads the logging packet from the translator.
        /// </summary>
        internal void ReadFromStream(INodePacketTranslator translator)
        {
            if (LoggingEventType.CustomEvent != _eventType)
            {
                _buildEvent = GetBuildEventArgFromId();

                // The other side is telling us whether the event knows how to log itself, or whether we're going to have 
                // to do it manually 
                int packetVersion = s_defaultPacketVersion;
                translator.Translate(ref packetVersion);

                bool eventCanSerializeItself = true;
                translator.Translate(ref eventCanSerializeItself);

                if (eventCanSerializeItself)
                {
                    MethodInfo methodInfo = null;
                    lock (s_readMethodCache)
                    {
                        if (!s_readMethodCache.TryGetValue(_eventType, out methodInfo))
                        {
                            Type eventDerivedType = _buildEvent.GetType();
                            methodInfo = eventDerivedType.GetMethod("CreateFromStream", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);
                            s_readMethodCache.Add(_eventType, methodInfo);
                        }
                    }

                    ArgsReaderDelegate readerMethod = (ArgsReaderDelegate)CreateDelegateRobust(typeof(ArgsReaderDelegate), _buildEvent, methodInfo);

                    readerMethod(translator.Reader, packetVersion);
                    if (_eventType == LoggingEventType.TargetFinishedEvent && _targetFinishedTranslator != null)
                    {
                        _targetFinishedTranslator(translator, (TargetFinishedEventArgs)_buildEvent);
                    }
                }
                else
                {
                    _buildEvent = ReadEventFromStream(_eventType, translator);
                }
            }
            else
            {
                string fileLocation = null;
                translator.Translate(ref fileLocation);

                bool resolveAssembly = false;
                lock (s_lockObject)
                {
                    if (!s_customEventsLoaded.Contains(fileLocation))
                    {
                        resolveAssembly = true;
                    }

                    // If we are to resolve the assembly add it to the list of assemblies resolved
                    if (resolveAssembly)
                    {
                        s_customEventsLoaded.Add(fileLocation);
                    }
                }

                if (resolveAssembly)
                {
                    s_resolver = new TaskEngineAssemblyResolver();
                    s_resolver.InstallHandler();
                    s_resolver.Initialize(fileLocation);
                }

                try
                {
                    translator.TranslateDotNet(ref _buildEvent);
                }
                finally
                {
                    if (resolveAssembly)
                    {
                        s_resolver.RemoveHandler();
                        s_resolver = null;
                    }
                }
            }

            _eventType = GetLoggingEventId(_buildEvent);
        }
コード例 #42
0
        /// <summary>
        /// Given a build event that is presumed to be 2.0 (due to its lack of a "ReadFromStream" method) and its 
        /// LoggingEventType, read that event from the stream. 
        /// </summary>
        private BuildEventArgs ReadEventFromStream(LoggingEventType eventType, INodePacketTranslator translator)
        {
            string message = null;
            string helpKeyword = null;
            string senderName = null;

            translator.Translate(ref message);
            translator.Translate(ref helpKeyword);
            translator.Translate(ref senderName);

            BuildEventArgs buildEvent = null;
            switch (eventType)
            {
                case LoggingEventType.TaskCommandLineEvent:
                    buildEvent = ReadTaskCommandLineEventFromStream(translator, message, helpKeyword, senderName);
                    break;
                case LoggingEventType.BuildErrorEvent:
                    buildEvent = ReadTaskBuildErrorEventFromStream(translator, message, helpKeyword, senderName);
                    break;
                case LoggingEventType.ProjectStartedEvent:
                    buildEvent = ReadExternalProjectStartedEventFromStream(translator, message, helpKeyword, senderName);
                    break;
                case LoggingEventType.ProjectFinishedEvent:
                    buildEvent = ReadExternalProjectFinishedEventFromStream(translator, message, helpKeyword, senderName);
                    break;
                case LoggingEventType.BuildMessageEvent:
                    buildEvent = ReadBuildMessageEventFromStream(translator, message, helpKeyword, senderName);
                    break;
                case LoggingEventType.BuildWarningEvent:
                    buildEvent = ReadBuildWarningEventFromStream(translator, message, helpKeyword, senderName);
                    break;
                default:
                    ErrorUtilities.ThrowInternalError("Not Supported LoggingEventType {0}", eventType.ToString());
                    break;
            }

            return buildEvent;
        }
コード例 #43
0
ファイル: LogEntry.cs プロジェクト: Enhakiel/redmine-net-api
 public LogEntry(LoggingEventType severity, string message, Exception exception = null)
 {
     Severity = severity;
     Message = message;
     Exception = exception;
 }
コード例 #44
0
 /// <summary>
 /// Encapsulates the buildEventArg in this packet.
 /// </summary>
 internal LogMessagePacketBase(KeyValuePair<int, BuildEventArgs>? nodeBuildEvent, TargetFinishedTranslator targetFinishedTranslator)
 {
     ErrorUtilities.VerifyThrow(nodeBuildEvent != null, "nodeBuildEvent was null");
     _buildEvent = nodeBuildEvent.Value.Value;
     _sinkId = nodeBuildEvent.Value.Key;
     _eventType = GetLoggingEventId(_buildEvent);
     _targetFinishedTranslator = targetFinishedTranslator;
 }