Class LogEvent.
Inheritance: NoSerializationVerificationNeeded
コード例 #1
0
ファイル: SerilogLogger.cs プロジェクト: njimenez/akka.net
 private ILogger SetContextFromLogEvent(ILogger logger, LogEvent logEvent)
 {
     logger.ForContext("Timestamp", logEvent.Timestamp);
     logger.ForContext("LogSource", logEvent.LogSource);
     logger.ForContext("Thread", logEvent.Thread);
     return logger;
 }
コード例 #2
0
 private ILogger GetLogger(LogEvent logEvent)
 {
     return(_logger.ForContext("Timestamp", logEvent.Timestamp)
            // .ForContext("LogSource","[" + logEvent.LogSource.Split('/').Last())
            .ForContext("LogSource", logEvent.LogSource)
            .ForContext("Thread", logEvent.Thread.ManagedThreadId));
 }
コード例 #3
0
ファイル: WarningFilter.cs プロジェクト: Micha-kun/akka.net
 protected override bool IsMatch(LogEvent evt)
 {
     var warning = evt as Warning;
     if(warning != null)
     {
         return InternalDoMatch(warning.LogSource, warning.Message);
     }
     return false;
 }
コード例 #4
0
ファイル: SerilogLogger.cs プロジェクト: skotzko/akka.net
        private ILogger SetContextFromLogEvent(ILogger logger, LogEvent logEvent)
        {
            logger = logger
                      .ForContext("Timestamp", logEvent.Timestamp)
                      .ForContext("LogSource", logEvent.LogSource)
                      .ForContext("Thread", logEvent.Thread.ManagedThreadId.ToString().PadLeft(4, '0'));

            return logger;
        }
コード例 #5
0
ファイル: EventFilterBase.cs プロジェクト: Micha-kun/akka.net
        protected abstract bool IsMatch(LogEvent evt);  //In Akka JVM this is called matches

        public bool Apply(LogEvent logEvent)
        {
            if(IsMatch(logEvent))
            {
                OnEventMatched(logEvent);
                return true;
            }

            return false;
        }
コード例 #6
0
ファイル: InfoFilter.cs プロジェクト: MaciekLesiczka/akka.net
        protected override bool IsMatch(LogEvent evt)
        {
            var info = evt as Info;
            if(info != null)
            {
                return InternalDoMatch(info.LogSource, info.Message);
            }

            return false;
        }
コード例 #7
0
ファイル: DebugFilter.cs プロジェクト: Micha-kun/akka.net
        protected override bool IsMatch(LogEvent evt)
        {
            var debug = evt as Debug;
            if(debug != null)
            {
                return InternalDoMatch(debug.LogSource, debug.Message);
            }

            return false;
        }
コード例 #8
0
ファイル: ErrorFilter.cs プロジェクト: njannink/sonarlint-vs
        protected override bool IsMatch(LogEvent evt)
        {
            var error = evt as Error;
            if(error != null)
            {
                var logSource = error.LogSource;
                var errorMessage = error.Message;
                var cause = error.Cause;
                return IsMatch(logSource, errorMessage, cause);
            }

            return false;
        }
コード例 #9
0
        protected override bool IsMatch(LogEvent evt)
        {
            var warning = evt as Warning;
            if(warning != null)
            {
                var deadLetter = warning.Message as DeadLetter;
                if(deadLetter != null)
                    if(_isMatch == null || _isMatch(deadLetter))
                        return InternalDoMatch(warning.LogSource, deadLetter.Message);
            }

            return false;
        }
コード例 #10
0
 protected override void Print(LogEvent m)
 {           
     if(m.Message is ForwardAllEventsTo)
     {
         _forwarder = ((ForwardAllEventsTo)m.Message).Forwarder;
         _forwarder.Tell("OK");
     }
     else if(_forwarder != null)
     {
         _forwarder.Forward(m);
     }
     else
     {
         base.Print(m);
     }
 }
コード例 #11
0
 public static void PrintLogEvent(LogEvent logEvent)
 {
     ConsoleColor? color = null;
     if(UseColors)
     {
         var logLevel = logEvent.LogLevel();
         switch(logLevel)
         {
             case LogLevel.DebugLevel:
                 color = DebugColor;
                 break;
             case LogLevel.InfoLevel:
                 color = InfoColor;
                 break;
             case LogLevel.WarningLevel:
                 color = WarningColor;
                 break;
             case LogLevel.ErrorLevel:
                 color = ErrorColor;
                 break;
         }
     }
     StandardOutWriter.WriteLine(logEvent.ToString(), color);
 }
コード例 #12
0
 /// <summary>
 ///     Publishes the specified event.
 /// </summary>
 /// <param name="event">The event.</param>
 private void Publish(LogEvent @event)
 {
     try
     {
         System.EventStream.Publish(@event);
     }
     catch
     {
         //TODO: Hmmm?
     }
 }
コード例 #13
0
 private void Log(LogEvent message)
 {
     Console.WriteLine("Log: {0}",message);
 }
コード例 #14
0
        /// <summary>
        /// Prints a specified event to the console.
        /// </summary>
        /// <param name="logEvent">The event to print</param>
        internal static void PrintLogEvent(LogEvent logEvent)
        {
            try
            {
                ConsoleColor?color = null;

                if (UseColors)
                {
                    var logLevel = logEvent.LogLevel();
                    switch (logLevel)
                    {
                    case LogLevel.DebugLevel:
                        color = DebugColor;
                        break;

                    case LogLevel.InfoLevel:
                        color = InfoColor;
                        break;

                    case LogLevel.WarningLevel:
                        color = WarningColor;
                        break;

                    case LogLevel.ErrorLevel:
                        color = ErrorColor;
                        break;
                    }
                }

                StandardOutWriter.WriteLine(logEvent.ToString(), color);
            }
            catch (FormatException ex)
            {
                /*
                 * If we've reached this point, the `logEvent` itself is formatted incorrectly.
                 * Therefore we have to treat the data inside the `logEvent` as suspicious and avoid throwing
                 * a second FormatException.
                 */
                var sb = new StringBuilder();
                sb.AppendFormat("[ERROR][{0}]", logEvent.Timestamp)
                .AppendFormat("[Thread {0}]", logEvent.Thread.ManagedThreadId.ToString().PadLeft(4, '0'))
                .AppendFormat("[{0}] ", nameof(StandardOutLogger))
                .AppendFormat("Encountered System.FormatException while recording log: [{0}]", logEvent.LogLevel().PrettyNameFor())
                .AppendFormat("[{0}]. ", logEvent.LogSource)
                .Append(ex.Message);

                string msg;
                switch (logEvent.Message)
                {
                case LogMessage formatted:     // a parameterized log
                    msg = " str=[" + formatted.Format + "], args=[" + string.Join(",", formatted.Args) + "]";
                    break;

                case string unformatted:     // pre-formatted or non-parameterized log
                    msg = unformatted;
                    break;

                default:     // surprise!
                    msg = logEvent.Message.ToString();
                    break;
                }

                sb.Append(msg)
                .Append(" Please take a look at the logging call where this occurred and fix your format string.");

                StandardOutWriter.WriteLine(sb.ToString(), ErrorColor);
            }
        }
コード例 #15
0
 protected override bool IsMatch(LogEvent evt)
 {
     return _predicate(evt);
 }
コード例 #16
0
 /// <summary>
 ///     Publishes the specified event.
 /// </summary>
 /// <param name="event">The event.</param>
 private void Publish(LogEvent @event)
 {
     try
     {
         System.EventStream.Publish(@event);
     }
     catch
     {
     }
 }
コード例 #17
0
ファイル: Slf4jLogger.cs プロジェクト: Badmoonz/akka.net
 private void WithMDC(string logSource, LogEvent logEvent, Action<ILogger> logStatement)
 {
     ILogger logger = LoggerFactory.GetLogger(GetType());
     logStatement(logger);
 }
コード例 #18
0
 protected virtual void Print(LogEvent logEvent)
 {
     StandardOutLogger.PrintLogEvent(logEvent);
 }
コード例 #19
0
ファイル: NLogLogger.cs プロジェクト: jweimann/akka.net
 private void WithNLog(string logSource, LogEvent logEvent, Action<Logger> logStatement)
 {
     var logger = LogManager.GetCurrentClassLogger();
     logStatement(logger);
 }
コード例 #20
0
ファイル: NLogLogger.cs プロジェクト: njimenez/akka.net
 private static void Log(LogEvent logEvent, Action<NLogger> logStatement)
 {
     var logger = LogManager.GetLogger(logEvent.LogClass.FullName);
     logStatement(logger);
 }
コード例 #21
0
ファイル: EventFilterBase.cs プロジェクト: Micha-kun/akka.net
 /// <summary>
 /// Determines whether the specified event should be filtered or not.
 /// </summary>
 /// <returns><c>true</c> to filter the event.</returns>
 protected abstract bool IsMatch(LogEvent evt);  //In Akka JVM this is called matches
コード例 #22
0
 /// <summary>
 /// Print the specified log event.
 /// </summary>
 /// <param name="logEvent">The log event that is to be output.</param>
 protected virtual void Print(LogEvent logEvent)
 {
     StandardOutLogger.PrintLogEvent(logEvent);
 }
コード例 #23
0
        private bool ShouldFilter(LogEvent message)
        {
            foreach(var filter in _filters)
            {
                try
                {
                    if(filter.Apply(message))
                        return true;
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch
                {
                }
            }
            return false;

        }
コード例 #24
0
ファイル: EventFilterBase.cs プロジェクト: Micha-kun/akka.net
 protected virtual void OnEventMatched(LogEvent logEvent)
 {
     var delegt = EventMatched;
     if(delegt != null) delegt(this, logEvent);
 }
コード例 #25
0
ファイル: EventStreamSpec.cs プロジェクト: skotzko/akka.net
        private void verifyLevel(LoggingBus bus, LogLevel level)
        {
            var allmsg = new LogEvent[] {
                new Debug("", null, "debug"),
                new Info("", null, "info"),
                new  Warning("", null, "warning"),
                new Error(null,"", null, "error")};

            var msg = allmsg.Where(l => l.LogLevel() >= level);
            allmsg.ToList().ForEach(l => bus.Publish(l));
            msg.ToList().ForEach(l => ExpectMsg(l));
        }
コード例 #26
0
 private void Publish(IActorContext context, LogEvent logEvent)
 {
     try
     {
         context.System.EventStream.Publish(logEvent);
     }
     catch (Exception)
     {
        // swallow any exceptions
     }
 }