Esempio n. 1
0
        public void LoggingLevelTest()
        {
            var loggerProvider = new MXLoggerProvider(WriteLine, LogLevel.Warning);
            var loggerFactory  = new LoggerFactory(new[] { loggerProvider });
            var logger         = loggerFactory.CreateLogger("category");

            logger.LogTrace("trace message");
            logger.LogDebug("debug message");
            logger.LogInformation("information message");
            logger.LogWarning("warning message");
            logger.LogError("error message");
            logger.LogCritical("critical message");
            Assert.Equal(3, loggerProvider.GetLogEntries().Count);
        }
Esempio n. 2
0
        public void Test()
        {
            var provider = new MXLoggerProvider(WriteLine);

            var serviceProvider = new ServiceCollection()
                                  .AddLogging(builder => builder.AddProvider(provider))
                                  .AddTransient <Component1>()
                                  .AddTransient <Component2>()
                                  .BuildServiceProvider();

            // inject ILogger<T>
            Component1 component1 = serviceProvider.GetService <Component1>() !;

            component1.Log("test");
            Assert.Equal("Info\t  MXLogger.xUnitTests.Component1\t  test\t  ", provider.Format(provider.GetLogEntries().Last()));

            // inject ILoggerFactory
            Component2 component2 = serviceProvider.GetService <Component2>() !;

            component2.Log("test");
            Assert.Equal("Info\t  Component2Name\t  test\t  ", provider.Format(provider.GetLogEntries().Last()));
        }