private ILogger SetContextFromLogEvent(ILogger logger, LogEvent logEvent) { logger.ForContext("Timestamp", logEvent.Timestamp); logger.ForContext("LogSource", logEvent.LogSource); logger.ForContext("Thread", logEvent.Thread); return logger; }
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)); }
protected override bool IsMatch(LogEvent evt) { var warning = evt as Warning; if(warning != null) { return InternalDoMatch(warning.LogSource, warning.Message); } return false; }
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; }
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; }
protected override bool IsMatch(LogEvent evt) { var info = evt as Info; if(info != null) { return InternalDoMatch(info.LogSource, info.Message); } return false; }
protected override bool IsMatch(LogEvent evt) { var debug = evt as Debug; if(debug != null) { return InternalDoMatch(debug.LogSource, debug.Message); } return false; }
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; }
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; }
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); } }
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); }
/// <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? } }
private void Log(LogEvent message) { Console.WriteLine("Log: {0}",message); }
/// <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); } }
protected override bool IsMatch(LogEvent evt) { return _predicate(evt); }
/// <summary> /// Publishes the specified event. /// </summary> /// <param name="event">The event.</param> private void Publish(LogEvent @event) { try { System.EventStream.Publish(@event); } catch { } }
private void WithMDC(string logSource, LogEvent logEvent, Action<ILogger> logStatement) { ILogger logger = LoggerFactory.GetLogger(GetType()); logStatement(logger); }
protected virtual void Print(LogEvent logEvent) { StandardOutLogger.PrintLogEvent(logEvent); }
private void WithNLog(string logSource, LogEvent logEvent, Action<Logger> logStatement) { var logger = LogManager.GetCurrentClassLogger(); logStatement(logger); }
private static void Log(LogEvent logEvent, Action<NLogger> logStatement) { var logger = LogManager.GetLogger(logEvent.LogClass.FullName); logStatement(logger); }
/// <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
/// <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); }
private bool ShouldFilter(LogEvent message) { foreach(var filter in _filters) { try { if(filter.Apply(message)) return true; } // ReSharper disable once EmptyGeneralCatchClause catch { } } return false; }
protected virtual void OnEventMatched(LogEvent logEvent) { var delegt = EventMatched; if(delegt != null) delegt(this, logEvent); }
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)); }
private void Publish(IActorContext context, LogEvent logEvent) { try { context.System.EventStream.Publish(logEvent); } catch (Exception) { // swallow any exceptions } }