Exemplo n.º 1
0
        /// <summary>
        /// Creates vital core service instances and registers them in <see cref="ServiceRegistration"/>. The optional <paramref name="dataDirectory"/> argument can
        /// be used to startup the application using a custom directory for data storage.
        /// </summary>
        /// <param name="dataDirectory">Path to custom data directory</param>
        public static void RegisterVitalCoreServices(string dataDirectory = null)
        {
            // Insert a dummy while loading the path manager to break circular dependency of logger and path manager. This should not
            // be considered as a hack - simply the logger needs a path managed by the path manager and I don't want to remove log
            // output from the path manager only to prevent the dependency. Maybe we have a better solution in the future.
            ServiceRegistration.Set <ILogger>(new NoLogger());

            Services.PathManager.PathManager pathManager = new Services.PathManager.PathManager();
            pathManager.InitializeDefaults();
            if (!string.IsNullOrEmpty(dataDirectory))
            {
                pathManager.SetPath("DATA", dataDirectory);
            }

            ServiceRegistration.Set <IPathManager>(pathManager);

            ILogger logger = new Log4NetLogger(pathManager.GetPath(@"<LOG>"));

            logger.Info("ApplicationCore: Launching in AppDomain {0}...", AppDomain.CurrentDomain.FriendlyName);

            // Assembly and build information
            FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetCallingAssembly().Location);

            logger.Info("ApplicationCore: Comments:   {0}", fileVersionInfo.Comments);
            logger.Info("ApplicationCore: Copyright:  {0}", fileVersionInfo.LegalCopyright);
            logger.Info("ApplicationCore: Version:    {0}", fileVersionInfo.FileVersion);
            logger.Info("ApplicationCore: Source:     {0}", fileVersionInfo.ProductVersion);
            logger.Info("ApplicationCore: ----------------------------------------------------------");

            logger.Debug("ApplicationCore: Registering ILogger service");
            ServiceRegistration.Set <ILogger>(logger);

            logger.Debug("ApplicationCore: Registering ISettingsManager service");
            ServiceRegistration.Set <ISettingsManager>(new SettingsManager());
        }
        public void When_logging_using_debug()
        {
            _logger.Debug("Hi");
            _mockedLogger.Verify(l => l.Debug("Hi"), Times.Once);

            var ex = new InvalidOperationException();

            _logger.Debug("Ooops", ex);
            _mockedLogger.Verify(l => l.Debug("Ooops", ex), Times.Once);
        }
Exemplo n.º 3
0
        public void CallingMethods()
        {
            var logMock = new LogMock();
            var logger  = new Log4NetLogger(logMock);
            var b       = logger.IsDebugEnabled;

            b = logger.IsErrorEnabled;
            b = logger.IsFatalEnabled;
            b = logger.IsInfoEnabled;
            b = logger.IsWarnEnabled;

            logger.Debug(null);
            logger.Debug(null, null);
            logger.DebugFormat(null, null);

            logger.Error(null);
            logger.Error(null, null);
            logger.ErrorFormat(null, null);

            logger.Warn(null);
            logger.Warn(null, null);
            logger.WarnFormat(null, null);

            logger.Info(null);
            logger.Info(null, null);
            logger.InfoFormat(null, null);

            logger.Fatal(null);
            logger.Fatal(null, null);

            Assert.That(logMock.debug, Is.EqualTo(1));
            Assert.That(logMock.debugException, Is.EqualTo(1));
            Assert.That(logMock.debugFormat, Is.EqualTo(1));
            Assert.That(logMock.info, Is.EqualTo(1));
            Assert.That(logMock.infoException, Is.EqualTo(1));
            Assert.That(logMock.infoFormat, Is.EqualTo(1));
            Assert.That(logMock.warn, Is.EqualTo(1));
            Assert.That(logMock.warnException, Is.EqualTo(1));
            Assert.That(logMock.warnFormat, Is.EqualTo(1));
            Assert.That(logMock.error, Is.EqualTo(1));
            Assert.That(logMock.errorException, Is.EqualTo(1));
            Assert.That(logMock.errorFormat, Is.EqualTo(1));
            Assert.That(logMock.fatal, Is.EqualTo(1));
            Assert.That(logMock.fatalException, Is.EqualTo(1));
            Assert.That(logMock.isDebugEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isInfoEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isWarnEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isErrorEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isFatalEnabled, Is.GreaterThan(1));
        }
Exemplo n.º 4
0
        public void CallingMethods()
        {
            var logMock = new LogMock();
            var logger  = new Log4NetLogger(logMock);
            var b       = logger.IsDebugEnabled;

            b = logger.IsErrorEnabled;
            b = logger.IsFatalEnabled;
            b = logger.IsInfoEnabled;
            b = logger.IsWarnEnabled;

            logger.Debug(null);
            logger.Debug(null, null);
            logger.DebugFormat(null, null);

            logger.Error(null);
            logger.Error(null, null);
            logger.ErrorFormat(null, null);

            logger.Warn(null);
            logger.Warn(null, null);
            logger.WarnFormat(null, null);

            logger.Info(null);
            logger.Info(null, null);
            logger.InfoFormat(null, null);

            logger.Fatal(null);
            logger.Fatal(null, null);

            logMock.debug.Should().Be(1);
            logMock.debugException.Should().Be(1);
            logMock.debugFormat.Should().Be(1);
            logMock.info.Should().Be(1);
            logMock.infoException.Should().Be(1);
            logMock.infoFormat.Should().Be(1);
            logMock.warn.Should().Be(1);
            logMock.warnException.Should().Be(1);
            logMock.warnFormat.Should().Be(1);
            logMock.error.Should().Be(1);
            logMock.errorException.Should().Be(1);
            logMock.errorFormat.Should().Be(1);
            logMock.fatal.Should().Be(1);
            logMock.fatalException.Should().Be(1);
            logMock.isDebugEnabled.Should().Be.GreaterThan(1);
            logMock.isInfoEnabled.Should().Be.GreaterThan(1);
            logMock.isWarnEnabled.Should().Be.GreaterThan(1);
            logMock.isErrorEnabled.Should().Be.GreaterThan(1);
            logMock.isFatalEnabled.Should().Be.GreaterThan(1);
        }
        private void RunDebugLogMessageTests(bool withFormattedMessage)
        {
            LogMessageExpectations logMessageExpectations =
                GenerateLogMessageExpectations(withFormattedMessage);

            TargetLoggerMockLoggerSetupProperties loggerSetupProps = TargetLoggerMockLoggerSetupProperties
                                                                     .DebugEnabledWithExpectations(logMessageExpectations);

            Mock <ILog> targetLoggerMock =
                CreateLog4NetLoggerMock(loggerSetupProps);

            Log4NetLogger stakhanoviseLogger =
                new Log4NetLogger(targetLoggerMock.Object);

            if (withFormattedMessage)
            {
                stakhanoviseLogger.DebugFormat(logMessageExpectations.ExpectedMessage, logMessageExpectations.ExpectedMessageArgs);
            }
            else
            {
                stakhanoviseLogger.Debug(logMessageExpectations.ExpectedMessage);
            }

            targetLoggerMock.Verify();
        }
 public void DebugShouldForwardsMessageToInnerDebug()
 {
     var message = "somemessage";
       var mockLog = new Mock<log4net.ILog>();
       mockLog.Setup(x => x.Debug(message)).Verifiable();
       ILog tested = new Log4NetLogger(mockLog.Object);
       tested.Debug(message);
       mockLog.Verify();
 }
Exemplo n.º 7
0
        public void WriteToConsoleTest()
        {
            Log4NetLogger logger = new Log4NetLogger();

            logger.Fatal("Fatal message");
            logger.Error("Error message");
            logger.Info("Info message");
            logger.Debug("Debug message");
        }
        public void DebugShouldForwardsMessageToInnerDebug()
        {
            var message = "somemessage";
            var mockLog = new Mock <log4net.ILog>();

            mockLog.Setup(x => x.Debug(message)).Verifiable();
            ILog tested = new Log4NetLogger(mockLog.Object);

            tested.Debug(message);
            mockLog.Verify();
        }
Exemplo n.º 9
0
 public void SimpleLogTest()
 {
     var myLogger = new Log4NetLogger(typeof(Log4NetLogger));
     myLogger.Debug("FooBar");
     myLogger.Warning("FooBar");
     myLogger.Error("FooBar");
     myLogger.Error(new Exception(), "FooBar");
     myLogger.Info("FooBar");
     myLogger.Info("FooBar", "Bar");
     Assert.AreEqual(myLogger.IsDebugEnabled, myLogger.IsDebugEnabled); // We don't care about the actual value.
 }
 public void FormattedDebugShouldForwardsMessageToInnerDebugFormat()
 {
     var format = "formatted message";
       var args = new object[] { "arg1", "arg2" };
       var provider = new Mock<IFormatProvider>().Object;
       var mockLog = new Mock<log4net.ILog>();
       mockLog.Setup(x => x.DebugFormat(provider, format, args)).Verifiable();
       ILog tested = new Log4NetLogger(mockLog.Object);
       tested.Debug(provider, format, args);
       mockLog.Verify();
 }
Exemplo n.º 11
0
        public void DefaultLogger_DebugLog_MessageExposedTest()
        {
            //Arrange
            var messages = new List <Tuple <LogLevel, string, Exception> >();
            var logger   = new Log4NetLogger("Test");

            logger.LogMessageHandler += (x, y, z) => messages.Add(new Tuple <LogLevel, string, Exception>(x, y, z));
            var testMessage   = "Test message";
            var testException = new Exception("Test");

            //Act
            logger.Debug(testMessage);
            logger.Debug(testException);
            logger.Debug(testMessage, testException);
            //Assert
            Assert.AreEqual(3, messages.Count);
            Assert.AreEqual(new Tuple <LogLevel, string, Exception>(LogLevel.Debug, testMessage, null), messages[0], "Log entry with message was not exposed correctly.");
            Assert.AreEqual(new Tuple <LogLevel, string, Exception>(LogLevel.Debug, string.Empty, testException), messages[1], "Log entry with exception was not exposed correctly.");
            Assert.AreEqual(new Tuple <LogLevel, string, Exception>(LogLevel.Debug, testMessage, testException), messages[2], "Log entry with message and exception was not exposed correctly.");
        }
Exemplo n.º 12
0
        public void SimpleLogTest()
        {
            var myLogger = new Log4NetLogger(typeof(Log4NetLogger));

            myLogger.Debug("FooBar");
            myLogger.Warning("FooBar");
            myLogger.Error("FooBar");
            myLogger.Error(new Exception(), "FooBar");
            myLogger.Info("FooBar");
            myLogger.Info("FooBar", "Bar");
            Assert.AreEqual(myLogger.IsDebugEnabled, myLogger.IsDebugEnabled); // We don't care about the actual value.
        }
        public void FormattedDebugShouldForwardsMessageToInnerDebugFormat()
        {
            var format   = "formatted message";
            var args     = new object[] { "arg1", "arg2" };
            var provider = new Mock <IFormatProvider>().Object;
            var mockLog  = new Mock <log4net.ILog>();

            mockLog.Setup(x => x.DebugFormat(provider, format, args)).Verifiable();
            ILog tested = new Log4NetLogger(mockLog.Object);

            tested.Debug(provider, format, args);
            mockLog.Verify();
        }
Exemplo n.º 14
0
        public void Debug_MessageOnly()
        {
            // Prepare
            const string message = "Simple Message";
            logger.SetupGet(o => o.IsDebugEnabled).Returns(() => true);
            logger.Setup(o => o.Debug(message)).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Debug(message);

            // Assert
            logger.VerifyAll();
        }
Exemplo n.º 15
0
        public void Debug_NoMessage()
        {
            // Prepare
            const string message = "Simple Message";
            logger.SetupGet(o => o.IsDebugEnabled).Returns(() => false);
            logger.Setup(o => o.Debug(message)).Callback(() => counterCall++);
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Debug(message);

            // Assert
            Assert.AreEqual(counterCall, 0);
        }
Exemplo n.º 16
0
        public void Debug_LambdaMessage()
        {
            // Prepare
            const string message = "Simple Message";

            logger.SetupGet(o => o.IsDebugEnabled).Returns(() => true);
            logger.Setup(o => o.Debug(message)).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Debug(() => message);

            // Assert
            logger.VerifyAll();
        }
Exemplo n.º 17
0
        public void Debug_NoMessage()
        {
            // Prepare
            const string message = "Simple Message";

            logger.SetupGet(o => o.IsDebugEnabled).Returns(() => false);
            logger.Setup(o => o.Debug(message)).Callback(() => counterCall++);
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Debug(message);

            // Assert
            Assert.AreEqual(counterCall, 0);
        }
Exemplo n.º 18
0
        public void Debug_MessageWithException()
        {
            // Prepare
            const string message = "Exception occurred";
            var          ex      = new Exception(message);

            logger.SetupGet(o => o.IsDebugEnabled).Returns(() => true);
            logger.Setup(o => o.Debug(message, ex)).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Debug(message, ex);

            // Assert
            logger.VerifyAll();
        }
Exemplo n.º 19
0
		public void CallingMethods()
		{
			var logMock = new LogMock();
			var logger = new Log4NetLogger(logMock);
			var b = logger.IsDebugEnabled;
			b = logger.IsErrorEnabled;
			b = logger.IsFatalEnabled;
			b = logger.IsInfoEnabled;
			b = logger.IsWarnEnabled;
			
			logger.Debug(null);
			logger.Debug(null, null);
			logger.DebugFormat(null, null);
			
			logger.Error(null);
			logger.Error(null, null);
			logger.ErrorFormat(null, null);
			
			logger.Warn(null);
			logger.Warn(null, null);
			logger.WarnFormat(null, null);
		
			logger.Info(null);
			logger.Info(null, null);
			logger.InfoFormat(null, null);

			logger.Fatal(null);
			logger.Fatal(null, null);

			logMock.debug.Should().Be(1);
			logMock.debugException.Should().Be(1);
			logMock.debugFormat.Should().Be(1);
			logMock.info.Should().Be(1);
			logMock.infoException.Should().Be(1);
			logMock.infoFormat.Should().Be(1);
			logMock.warn.Should().Be(1);
			logMock.warnException.Should().Be(1);
			logMock.warnFormat.Should().Be(1);
			logMock.error.Should().Be(1);
			logMock.errorException.Should().Be(1);
			logMock.errorFormat.Should().Be(1);
			logMock.fatal.Should().Be(1);
			logMock.fatalException.Should().Be(1);
			logMock.isDebugEnabled.Should().Be.GreaterThan(1);
			logMock.isInfoEnabled.Should().Be.GreaterThan(1);
			logMock.isWarnEnabled.Should().Be.GreaterThan(1);
			logMock.isErrorEnabled.Should().Be.GreaterThan(1);
			logMock.isFatalEnabled.Should().Be.GreaterThan(1);
		}
Exemplo n.º 20
0
 public void Test()
 {
     Logger.Debug("This log message should have a prepended category");
 }
Exemplo n.º 21
0
 public void DebugInfo(string debugInfo)
 {
     Log4NetLogger.Debug(debugInfo);
 }
Exemplo n.º 22
0
        public void Debug_MessageWithException()
        {
            // Prepare
            const string message = "Exception occurred";
            var ex = new Exception(message);
            logger.SetupGet(o => o.IsDebugEnabled).Returns(() => true);
            logger.Setup(o => o.Debug(message, ex)).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Debug(message, ex);

            // Assert
            logger.VerifyAll();
        }
Exemplo n.º 23
0
        /// <summary>
        /// Creates core service instances and registers them in <see cref="ServiceRegistration"/>. The optional <paramref name="dataDirectory"/> argument can
        /// be used to startup the application using a custom directory for data storage.
        /// </summary>
        /// <param name="dataDirectory">Path to custom data directory</param>
        public static void RegisterCoreServices(string dataDirectory = null)
        {
            // Insert a dummy while loading the path manager to break circular dependency of logger and path manager. This should not
            // be considered as a hack - simply the logger needs a path managed by the path manager and I don't want to remove log
            // output from the path manager only to prevent the dependency. Maybe we have a better solution in the future.
            ServiceRegistration.Set <ILogger>(new NoLogger());

            Services.PathManager.PathManager pathManager = new Services.PathManager.PathManager();
            pathManager.InitializeDefaults();
            if (!string.IsNullOrEmpty(dataDirectory))
            {
                pathManager.SetPath("DATA", dataDirectory);
            }

            ServiceRegistration.Set <IPathManager>(pathManager);

            ILogger logger = new Log4NetLogger(pathManager.GetPath(@"<LOG>"));

            logger.Info("ApplicationCore: Launching in AppDomain {0}...", AppDomain.CurrentDomain.FriendlyName);

            logger.Debug("ApplicationCore: Registering ILogger service");
            ServiceRegistration.Set <ILogger>(logger);

            logger.Debug("ApplicationCore: Registering IRegistry service");
            ServiceRegistration.Set <IRegistry>(new Services.Registry.Registry());

            logger.Debug("ApplicationCore: Registering IThreadPool service");
            ServiceRegistration.Set <IThreadPool>(new ThreadPool());

            logger.Debug("ApplicationCore: Registering IMessageBroker service");
            ServiceRegistration.Set <IMessageBroker>(new MessageBroker());

            logger.Debug("ApplicationCore: Registering IPluginManager service");
            ServiceRegistration.Set <IPluginManager>(new Services.PluginManager.PluginManager());

            logger.Debug("ApplicationCore: Registering ISettingsManager service");
            ServiceRegistration.Set <ISettingsManager>(new SettingsManager());

            logger.Debug("ApplicationCore: Registering ILocalization service");
            ServiceRegistration.Set <ILocalization>(new StringManager());

            logger.Debug("ApplicationCore: Registering ITaskScheduler service");
            ServiceRegistration.Set <ITaskScheduler>(new Services.TaskScheduler.TaskScheduler());

            logger.Debug("ApplicationCore: Registering IMediaAccessor service");
            ServiceRegistration.Set <IMediaAccessor>(new MediaAccessor());

            logger.Debug("ApplicationCore: Registering IImporterWorker service");
            ServiceRegistration.Set <IImporterWorker>(new ImporterWorker());

            logger.Debug("ApplicationCore: Registering IResourceServer service");
            ServiceRegistration.Set <IResourceServer>(new ResourceServer());

            logger.Debug("ApplicationCore: Registering IResourceMountingService");
            ServiceRegistration.Set <IResourceMountingService>(new ResourceMountingService());

            logger.Debug("ApplicationCore: Registering IRemoteResourceInformationService");
            ServiceRegistration.Set <IRemoteResourceInformationService>(new RemoteResourceInformationService());

            logger.Debug("ApplicationCore: Registering IThumbnailGenerator service");
            ServiceRegistration.Set <IThumbnailGenerator>(new ThumbnailGenerator());

            AdditionalPluginItemBuilders.Register();
        }
Exemplo n.º 24
0
		public void CallingMethods()
		{
			var logMock = new LogMock();
			var logger = new Log4NetLogger(logMock);
			var b = logger.IsDebugEnabled;
			b = logger.IsErrorEnabled;
			b = logger.IsFatalEnabled;
			b = logger.IsInfoEnabled;
			b = logger.IsWarnEnabled;
			
			logger.Debug(null);
			logger.Debug(null, null);
			logger.DebugFormat(null, null);
			
			logger.Error(null);
			logger.Error(null, null);
			logger.ErrorFormat(null, null);
			
			logger.Warn(null);
			logger.Warn(null, null);
			logger.WarnFormat(null, null);
		
			logger.Info(null);
			logger.Info(null, null);
			logger.InfoFormat(null, null);

			logger.Fatal(null);
			logger.Fatal(null, null);

			Assert.That(logMock.debug, Is.EqualTo(1));
			Assert.That(logMock.debugException, Is.EqualTo(1));
			Assert.That(logMock.debugFormat, Is.EqualTo(1));
			Assert.That(logMock.info, Is.EqualTo(1));
			Assert.That(logMock.infoException, Is.EqualTo(1));
			Assert.That(logMock.infoFormat, Is.EqualTo(1));
			Assert.That(logMock.warn, Is.EqualTo(1));
			Assert.That(logMock.warnException, Is.EqualTo(1));
			Assert.That(logMock.warnFormat, Is.EqualTo(1));
			Assert.That(logMock.error, Is.EqualTo(1));
			Assert.That(logMock.errorException, Is.EqualTo(1));
			Assert.That(logMock.errorFormat, Is.EqualTo(1));
			Assert.That(logMock.fatal, Is.EqualTo(1));
			Assert.That(logMock.fatalException, Is.EqualTo(1));
			Assert.That(logMock.isDebugEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isInfoEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isWarnEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isErrorEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isFatalEnabled, Is.GreaterThan(1));
		}