public void Send(ICollection <LogzioLoggingEvent> logz, BulkSenderOptions options, int attempt = 0) { if (logz == null || logz.Count == 0) { return; } var url = string.Format(UrlTemplate, options.ListenerUrl, options.Token, options.Type); try { using (var client = _webClientFactory.GetWebClient()) { var serializedLogLines = logz.Select(x => Serialize(x.LogData)).ToArray(); var body = String.Join(Environment.NewLine, serializedLogLines); client.UploadString(url, body); if (options.Debug) { _internalLogger.Log("Sent bulk of [{0}] log messages to [{1}] successfully.", logz.Count, url); } } } catch (Exception ex) { if (options.Debug) { _internalLogger.Log("Logzio.DotNet ERROR: " + ex); } if (attempt < options.RetriesMaxAttempts - 1) { Task.Delay(options.RetriesInterval).ContinueWith(task => Send(logz, options, attempt + 1)); } } }
public static void Log(this IInternalLogger logger, string message) { #if !NET45 logger.Log(null, message, Array.Empty <object>()); #else logger.Log(null, message); #endif }
public override void ChannelRead(IChannelHandlerContext ctx, object msg) { var buffer = msg as IByteBuffer; if (buffer != null) { if (Logger.IsEnabled(InternalLevel)) { Logger.Log(InternalLevel, FormatByteBuffer("RECV", buffer)); } } ctx.FireChannelRead(msg); }
private void WriteImpl(LoggingEvent loggingEvent) { try { var values = new Dictionary <string, object> { { "@timestamp", loggingEvent.TimeStamp.ToString("o") }, { "logger", loggingEvent.LoggerName }, { "domain", loggingEvent.Domain }, { "level", loggingEvent.Level.DisplayName }, { "thread", loggingEvent.ThreadName }, { "message", loggingEvent.RenderedMessage }, { "exception", loggingEvent.GetExceptionString() }, { "processId", ProcessId } }; foreach (var customField in _customFields) { values[customField.Key] = customField.Value; } var properties = loggingEvent.GetProperties(); foreach (DictionaryEntry property in properties) { var value = property.Value; if (value == null || ReferenceEquals(value, "")) { continue; } var key = property.Key?.ToString() ?? string.Empty; key = key.Replace(":", "").Replace(".", "").Replace("log4net", ""); if (!string.IsNullOrEmpty(key)) { values[key] = value; } } ExtendValues(loggingEvent, values); _shipper.Ship(new LogzioLoggingEvent(values), _shipperOptions); } catch (Exception ex) { _internalLogger?.Log(ex, "Logz.io: Couldn't handle log message"); } }
public bool ReadConfiguration(IXmlSettingsProvider outputXmlConfiguration) { var settingsReader = _settingReaderFactory.GetSettingReader(outputXmlConfiguration); _filePath = settingsReader.GetSetting("filePath"); if (string.IsNullOrWhiteSpace(_filePath) == false) { _internalLogger.Log("'filePath' needs to be specified."); return(false); } return(true); }
public void Log(Exception ex, string message, params object[] args) { if (ex != null) { log4net.Util.LogLog.Debug(typeof(LogzioAppender), args?.Length > 0 ? string.Format(message, args) : message, ex); } if (_shipperOptions.Debug) { _internalLogger?.Log(ex, message, args); } }
public void Ship(LogzioLoggingEvent logzioLoggingEvent, ShipperOptions options) { _queue.Enqueue(logzioLoggingEvent); if (options.Debug) { _internalLogger.Log("Logz.io: Added log message. Queue size - [{0}]", _queue.Count); } SendLogsIfBufferIsFull(options); if (_delayTask == null || _delayTask.IsCompleted) { _delayTask = Task.Delay(options.BufferTimeLimit).ContinueWith(task => SendLogsIfBufferTimedOut(options)); } }
public bool ReadConfiguration(IXmlSettingsProvider outputXmlConfiguration) { var nodes = outputXmlConfiguration.GetNodesForKey("color"); for (var i = 0; i < nodes.Count; i++) { var node = nodes[i]; var colorForLevelSettingReader = _settingReaderFactory.GetSettingReader( _xmlSettingsProviderFactory.GetXmlSettingsProvider(node)); Level level; if (colorForLevelSettingReader.ReadSetting("[for]", (string s, out Level o) => { if (Enum.TryParse(s, out o) == false) { _internalLogger.Log("Unknown level type specifier '{0}' for color.", s); return(false); } return(true); }, out level) == false) { continue; } ConsoleColor consoleColor; if (colorForLevelSettingReader.ReadSetting("[for]", (string s, out ConsoleColor o) => { if (Enum.TryParse(s, out o) == false) { _internalLogger.Log("Unknown color specifier '{0}' for color.", s); return(false); } return(true); }, out consoleColor) == false) { continue; } _levelColors[level] = consoleColor; } return(true); }
public void Log(Exception ex, string message, params object[] args) { if (ex != null) { InternalLogger.Warn(ex, message, args); } else { InternalLogger.Trace(message, args); } if (_shipperOptions.Debug) { _internalLogger?.Log(ex, message, args); } }
public void Ship(LogzioLoggingEvent logzioLoggingEvent, ShipperOptions options) { // ReSharper disable once InconsistentlySynchronizedField _queue.Enqueue(logzioLoggingEvent); if (options.Debug) { _internalLogger.Log("Added log message. Queue size - [{0}]", _queue.Count); } SendLogsIfBufferIsFull(options); if (_delayTask == null || _delayTask.IsCompleted) { _delayTask = Task.Delay(options.BufferTimeLimit).ContinueWith(task => SendLogsIfBufferTimedOut(options)); } }
private void WriteImpl(LogEventInfo logEvent) { try { var values = new Dictionary <string, object> { { "@timestamp", logEvent.TimeStamp.ToString("o") }, { "logger", logEvent.LoggerName }, { "level", logEvent.Level.Name }, { "message", logEvent.FormattedMessage }, { "exception", logEvent.Exception?.ToString() }, { "sequenceId", logEvent.SequenceID.ToString() } }; foreach (var pair in logEvent.Properties.Where(pair => pair.Key != null)) { values[pair.Key.ToString()] = pair.Value; } foreach (var pair in LogManager.Configuration.Variables.Where(pair => pair.Key != null)) { values[pair.Key] = pair.Value?.OriginalText; } ExtendValues(logEvent, values); _shipper.Ship(new LogzioLoggingEvent(values), _shipperOptions); } catch (Exception ex) { if (Debug) { _internalLogger.Log("Couldn't handle log message: " + ex); } } }
public void LogData(Direction direction, IChannelHandlerContext ctx, int streamId, IByteBuffer data, int padding, bool endStream) { if (IsEnabled()) { _logger.Log(_level, "{} {} DATA: streamId={} padding={} endStream={} length={} bytes={}", ctx.Channel, direction, streamId, padding, endStream, data.ReadableBytes, ToString(data)); } }
protected override void Write(LogEventInfo logEvent) { try { var values = new Dictionary <string, object> { { "@timestamp", logEvent.TimeStamp.ToString("o") }, { "logger", logEvent.LoggerName }, { "level", logEvent.Level.Name }, { "message", _usingDefaultLayout ? logEvent.FormattedMessage : RenderLogEvent(Layout, logEvent) }, { "exception", logEvent.Exception?.ToString() }, { "sequenceId", logEvent.SequenceID.ToString() } }; if (ShouldIncludeProperties(logEvent)) { var properties = GetAllProperties(logEvent); foreach (var property in properties) { string key = property.Key; if (string.IsNullOrEmpty(key)) { continue; } if (key.IndexOf('.') != -1) { key = key.Replace('.', '_'); } if (key.IndexOf(':') != -1) { key = key.Replace(':', '_'); } if (values.ContainsKey(key)) { string newKey = string.Concat(key, "_1"); int i = 1; while (values.ContainsKey(newKey)) { i++; newKey = string.Concat(key, "_", i.ToString("d")); } key = newKey; } values[key] = property.Value; } } else if (ContextProperties.Count > 0) { for (int i = 0; i < ContextProperties.Count; ++i) { var property = ContextProperties[i]; var propertyValue = RenderLogEvent(property.Layout, logEvent); if (property.IncludeEmptyValue || !string.IsNullOrEmpty(propertyValue)) { values[property.Name] = propertyValue; } } } ExtendValues(logEvent, values); _shipper.Ship(new LogzioLoggingEvent(values), _shipperOptions); } catch (Exception ex) { _internalLogger?.Log(ex, "Logz.io: Couldn't handle log message"); throw; // Notify the NLog engine about this error } }
public static void Log(this IInternalLogger logger, string message, params object[] args) { logger.Log(null, message, args); }
public void Minimal(string message) { CheckLoggerCreated(); _inner.Log(LogLevel.Minimal, message); }
private void log(InternalLogLevel logLevel, object msg) { Logger.Log(logLevel, msg?.ToString()); }
public bool Read(out Configuration configuration) { XmlElement xmlConfiguration; try { var xmlDocument = new XmlDocument(); xmlDocument.Load(_filePath); xmlConfiguration = xmlDocument.DocumentElement; } catch (Exception exception) { _internalLogger.Log(exception, "Unable to read file at '{0}'.", _filePath); configuration = null; return(false); } var xmlSettingsProvider = _settingsProviderFactory.GetXmlSettingsProvider(xmlConfiguration); var globalSettingsReader = _settingReaderFactory.GetSettingReader(xmlSettingsProvider); bool enabled; if (globalSettingsReader.ReadSetting("/logging[enabled]", () => true, (string s, out bool o) => bool.TryParse(s, out o), out enabled) == false) { _internalLogger.Log("Unable to read setting for xpath '/logging[enabled]'. " + "Will use '{0}' value for it.", enabled); } configuration = new Configuration { Enabled = enabled, OutputPipes = new List <OutputPipe>() }; var firstMinimumLevelSet = false; var nodes = xmlSettingsProvider.GetNodesForKey("/logging/output"); for (var i = 0; i < nodes.Count; i++) { var outputXmlConfiguration = _settingsProviderFactory.GetXmlSettingsProvider(nodes[i]); var outputSettingsReader = _settingReaderFactory.GetSettingReader(outputXmlConfiguration); var type = outputSettingsReader.GetSetting("type"); IOutput output = null; if (!string.IsNullOrWhiteSpace(type)) { output = _outputs.FirstOrDefault( x => String.Compare(x.Type, type, StringComparison.OrdinalIgnoreCase) == 0); } if (output == null) { _internalLogger.Log("Unable to read an output configuration with attribute type '{0}'. " + "The type must be specifying valid logging output engine.'. ", type); continue; } var outputPipe = new OutputPipe { Output = output, Queue = _queueFactory.GetQueue(), OutputEngine = output.GetEngine() }; if (outputPipe.OutputEngine.ReadConfiguration(outputXmlConfiguration)) { _internalLogger.Log("Unable to read an output configuration with attribute type '{0}'.", type); continue; } TimeSpan bufferMaximumKeepTime; if (globalSettingsReader.ReadSetting("bufferMaximumKeepTime", () => new TimeSpan(0, 0, 0, 25), (string s, out TimeSpan o) => TimeSpan.TryParse(s, out o), out bufferMaximumKeepTime) == false) { _internalLogger.Log("Unable to attribute 'bufferMaximumKeepTime' for output of type '{0}'. " + "Will use '{1}' value for it.", type, bufferMaximumKeepTime); } outputPipe.BufferMaximumKeepTime = bufferMaximumKeepTime; configuration.OutputPipes.Add(outputPipe); Level minimumLogLevel; if (globalSettingsReader.ReadSetting("minimumLogLevel", () => Level.Debug, (string s, out Level o) => Enum.TryParse(s, out o), out minimumLogLevel) == false) { _internalLogger.Log("Unable to attribute 'minimumLogLevel' for output of type '{0}'. " + "Will use '{1}' value for it.", type, minimumLogLevel); } outputPipe.MinimumLogLevel = minimumLogLevel; if (firstMinimumLevelSet == false) { firstMinimumLevelSet = true; configuration.MinimumLogLevel = outputPipe.MinimumLogLevel; } else if (outputPipe.MinimumLogLevel < configuration.MinimumLogLevel) { configuration.MinimumLogLevel = outputPipe.MinimumLogLevel; } } return(true); }
public override void ChannelRegistered(IChannelHandlerContext ctx) { if (Logger.IsEnabled(InternalLevel)) { Logger.Log(InternalLevel, Format(ctx, "REGISTERED")); } ctx.FireChannelRegistered(); }