Esempio n. 1
0
 /// <summary>
 /// Create a new event instance
 /// </summary>
 public CapturingLoggerEvent(CapturingLogger source, LogLevel level, object messageObject, Exception exception)
 {
     Source        = source;
     Level         = level;
     MessageObject = messageObject;
     Exception     = exception;
 }
Esempio n. 2
0
 public CapturingLoggerEvent(CapturingLogger source, LogLevel level, object messageObject, Exception exception)
 {
     Source = source;
     Level = level;
     MessageObject = messageObject;
     Exception = exception;
 }
        public void LoggerCanChangeLogLevel()
        {
            CapturingLoggerFactoryAdapter adapter = new CapturingLoggerFactoryAdapter();
            CapturingLogger testLogger            = (CapturingLogger)adapter.GetLogger("test");

            Assert.AreEqual(LogLevel.All, testLogger.CurrentLogLevel);
            testLogger.Trace("message1");
            Assert.AreEqual(1, testLogger.LoggerEvents.Count);
            testLogger.CurrentLogLevel = LogLevel.Debug;
            testLogger.Trace("message2"); // not logged!
            Assert.AreEqual("message1", testLogger.LastEvent.MessageObject);
        }
        public void AdapterClearsEvents()
        {
            CapturingLoggerFactoryAdapter adapter = new CapturingLoggerFactoryAdapter();
            CapturingLogger testLogger            = (CapturingLogger)adapter.GetLogger("test");

            testLogger.Trace("message1");
            testLogger.Trace("message2");
            Assert.IsNotNull(adapter.LastEvent);
            Assert.AreEqual(2, adapter.LoggerEvents.Count);

            adapter.ClearLastEvent();
            Assert.IsNull(adapter.LastEvent);
            adapter.Clear();
            Assert.IsNull(adapter.LastEvent);
            Assert.AreEqual(0, adapter.LoggerEvents.Count);
        }
        /// <summary>
        /// Get a <see cref="CapturingLogger"/> instance for the given key.
        /// </summary>
        public ILog GetLogger(string name)
        {
            ILog logger;

            if (!_cachedLoggers.TryGetValue(name, out logger))
            {
                lock (((ICollection)_cachedLoggers).SyncRoot)
                {
                    if (!_cachedLoggers.TryGetValue(name, out logger))
                    {
                        logger = new CapturingLogger(this, name);
                        _cachedLoggers[name] = logger;
                    }
                }
            }
            return(logger);
        }
 public ILog GetLogger(string name)
 {
     ILog log = (ILog)_cachedLoggers[name];
     if (log == null)
     {
         lock (_cachedLoggers.SyncRoot)
         {
             log = (ILog)_cachedLoggers[name];
             if (log == null)
             {
                 log = new CapturingLogger(this, name);
                 _cachedLoggers[name] = log;
             }
         }
     }
     return log;
 }
        /// <summary>
        /// Get a <see cref="CapturingLogger"/> instance for the given name.
        /// </summary>
        public ILog GetLogger(string name)
        {
            ILog logger = (ILog)_cachedLoggers[name];

            if (logger == null)
            {
                lock (_cachedLoggers.SyncRoot)
                {
                    logger = (ILog)_cachedLoggers[name];
                    if (logger == null)
                    {
                        logger = new CapturingLogger(this, name);
                        _cachedLoggers[name] = logger;
                    }
                }
            }
            return(logger);
        }
        public void LoggerCapturesIndividualEvents()
        {
            CapturingLoggerFactoryAdapter adapter = new CapturingLoggerFactoryAdapter();
            CapturingLogger testLogger            = (CapturingLogger)adapter.GetLogger("test");

            testLogger.Trace("message1");
            testLogger.Trace("message2");

            Assert.AreEqual(2, testLogger.LoggerEvents.Count);
            Assert.AreEqual("message2", testLogger.LastEvent.MessageObject);
            Assert.AreEqual("message1", testLogger.LoggerEvents[0].MessageObject);
            Assert.AreEqual("message2", testLogger.LoggerEvents[1].MessageObject);

            testLogger.ClearLastEvent();
            Assert.IsNull(testLogger.LastEvent);
            testLogger.Clear();
            Assert.IsNull(testLogger.LastEvent);
            Assert.AreEqual(0, testLogger.LoggerEvents.Count);
        }
        public void AdapterCapturesAllEvents()
        {
            CapturingLoggerFactoryAdapter adapter = new CapturingLoggerFactoryAdapter();
            CapturingLogger testLogger            = (CapturingLogger)adapter.GetLogger("test");
            CapturingLogger test2Logger           = (CapturingLogger)adapter.GetLogger("test2");

            testLogger.Trace("message1");
            test2Logger.Trace("message2");

            Assert.AreEqual(1, testLogger.LoggerEvents.Count);
            Assert.AreEqual("message1", testLogger.LastEvent.MessageObject);
            Assert.AreEqual(1, test2Logger.LoggerEvents.Count);
            Assert.AreEqual("message2", test2Logger.LastEvent.MessageObject);

            Assert.AreEqual(2, adapter.LoggerEvents.Count);
            Assert.AreEqual("message1", adapter.LoggerEvents[0].MessageObject);
            Assert.AreEqual(1, test2Logger.LoggerEvents.Count);
            Assert.AreEqual("message2", adapter.LoggerEvents[1].MessageObject);
        }
 /// <summary>
 /// Get a <see cref="CapturingLogger"/> instance for the given key.
 /// </summary>
 public ILog GetLogger(string name)
 {
     ILog logger;
     if(!_cachedLoggers.TryGetValue(name, out logger))
     {
         lock (((ICollection)_cachedLoggers).SyncRoot)
         {
             if (!_cachedLoggers.TryGetValue(name, out logger))
             {
                 logger = new CapturingLogger(this, name);
                 _cachedLoggers[name] = logger;
             }
         }
     }
     return logger;
 }