protected override void OnClose() { base.OnClose(); var logger = RedisLogger.Get(Host, Port, Topic); if (logger != null) { logger.Dispose(); } }
/// <summary> /// Writes the logging event to redis /// </summary> protected override void Append(LoggingEvent evt) { var logger = RedisLogger.Get(Host, Port, Topic, true); if (logger != null) { var writer = new StringWriter(); Layout.Format(writer, evt); logger.Log($"{Topic}/{evt.LoggerName}/{evt.Level}", writer.ToString()); } }
public static RedisLogger Get(string host, int port, string topic, bool create = false) { RedisLogger logger; var key = $"{host}_{port}_{topic}"; lock (_loggers) { if (!_loggers.TryGetValue(key, out logger) && create) { logger = new RedisLogger(host, port); logger.Init(); _loggers[key] = logger; logger.Start(); } } return(logger); }