コード例 #1
0
        protected override void OnClose()
        {
            base.OnClose();

            var logger = RedisLogger.Get(Host, Port, Topic);

            if (logger != null)
            {
                logger.Dispose();
            }
        }
コード例 #2
0
        /// <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());
            }
        }
コード例 #3
0
ファイル: RedisLogger.cs プロジェクト: m3l3m01t/Log2Redis
        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);
        }